/*
* [MenuItem.java]
*
* Summary: Generate a menu item reference, three columns, image short/long description.
*
* 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.
*/
package com.mindprod.htmlmacros.macro;
import com.mindprod.fastcat.FastCat;
import com.mindprod.htmlmacros.support.BuildImage;
import com.mindprod.htmlmacros.support.ImageAlignment;
import com.mindprod.htmlmacros.support.Tools;
import java.io.File;
import static com.mindprod.htmlmacros.macro.Global.configuration;
import static java.lang.System.*;
/**
* Generate a menu item reference, three columns, image short/long description.
*
* @author Roedy Green, Canadian Mind Products
* @version 1.8 2009-02-06 include go package in ZIP bundle.
* @since 2009
*/
public final class MenuItem extends Macro
{
/**
* how to use the macro
*/
private static final String USAGE = "\nMenuItem macro needs targetFile image shortDesc longDesc";
// separator line
private static final String WALL =
"
| \n"
+ " | \n"
+ ""
+ configuration.getHr()
+ " | \n"
+ "
\n";
// used to track whether need top bar on first item.
private static File prevFile = null;
/**
* guts to Generate reference to a MenuItem reference
*
* @param targetFile name of file to jump to
* @param image image representing the file.
* @param shortDesc short description
* @param longDesc long description
* @param firstOnPage true if this is the first such menuItem on the page . It does not need a lead hr. *
*
* @return expand lines table followed by divider line
*/
private String expand( String targetFile,
String image,
String shortDesc,
String longDesc,
boolean firstOnPage )
{
final boolean hasTarget = !( targetFile == null || targetFile
.equals( "null" ) );
final boolean needLastMod =
hasTarget && !( targetFile.startsWith( "http:" ) || targetFile
.startsWith( "mailto:" ) );
final FastCat sb = new FastCat( 34 );
if ( firstOnPage )
{
sb.append( WALL );
}
if ( hasTarget )
{
sb.append( "" + "\n" );
sb.append( "\n" );
sb.append( "
\n" );
}
else
{
sb.append( "" + "\n" + "\n" + "
\n" );
}
sb.append( WALL );
return sb.toString();
}
/**
* Generate MenuItem to jump to a file. typical use:
*
* @param parms parms[0] targetFile name of file to jump to. null means none. parms[3] image
* representing the file. parms[1] shortDesc short description parms[2] longDesc long
* description
* @param quiet true if want output suppressed.
* @param verbose @return expanded macro HTML
*/
public String expandMacro( String[] parms, final boolean quiet, final boolean verbose )
{
if ( !quiet )
{
out.print( "I" );
}
if ( parms.length != 4 )
{
throw new IllegalArgumentException( USAGE );
}
String targetFile = parms[ 0 ];// no toLowerCase. may be offsite
// reference.
String image = parms[ 1 ];
String shortDesc = parms[ 2 ];
String longDesc = parms[ 3 ];
boolean firstOnPage;
if ( prevFile == fileBeingDistributed )
{
firstOnPage = false;
}
else
{
firstOnPage = true;
prevFile = fileBeingDistributed;
}
return expand( targetFile,
image,
shortDesc,
longDesc,
firstOnPage );
}
}