/* * [WaysToRender.java] * * Summary: Various ways to do displays. Finds best fit in a given case that uses the least screen real estate. * * 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.7 2009-04-12 shorter style names, improved highlighting. */ package com.mindprod.jdisplayaux; import com.mindprod.jdisplay.Footprint; import com.mindprod.jdisplay.Geometry; import com.mindprod.jdisplay.Rendering; import static java.lang.Math.min; import static java.lang.System.*; /** * Various ways to do displays. Finds best fit in a given case that uses the least screen real estate. * * @author Roedy Green, Canadian Mind Products * @version 1.7 2009-04-12 shorter style names, improved highlighting. * @since 2009 */ public enum WaysToRender { /** * Display is done without the JDisplay Applet. Generates HTML inline. */ INLINED( Rendering.INLINE, // rendering false, // bar false, // v false, // h 0, // minwidth 0, // minheight 800, // maxwidth 250, // maxheight 0, // minLines 16// maxLines ), /** * Display with non scrolling iframe. */ IFRAMED( Rendering.IFRAME, // rendering false, // bar false, // v false, // h 60, // minwidth 60, // minheight 800, // maxwidth 700, // maxheight 1, // minlines 47// maxlines ), /** * Display with small scrolling iframe. */ SMALLSCROLLINGIFRAME( Rendering.IFRAME, // rendering false, // bar true, // v true, // h 60, // minwidth 60, // minheight 800, // maxwidth 600, // maxheight 1, // minLines 100// maxLines ), /** * Display with large scrolling iframe. */ LARGESCROLLINGIFRAME( Rendering.IFRAME, // rendering false, // bar true, // v true, // h 60, // minwidth 60, // minheight 800, // maxwidth 700, // maxheight 1, // minLines 500// maxLines ), /** * Display has a menu bar but no scrollbars, uses Applet */ UNBARRED( Rendering.APPLET, // rendering false, // bar false, // v false, // h 60, // minwidth 60, // minheight 800, // maxwidth 600, // maxheight 1, // minLines 999999// maxLines ), /** * Display has a menu bar but no scrollbars */ BARRED( Rendering.APPLET, // rendering using Applet true, // bar false, // v false, // h 230, // minwidth 60, // minheight 800, // maxwidth 600, // maxheight 1, // minLines 999999// maxLines ), /** * Display his scrolled, horizontally, has menu bar */ SCROLLEDH( Rendering.APPLET, // rendering using Applet true, // bar false, // v true, // h 230, // minwidth 75, // minheight 800, // maxwidth 600, // maxheight 1, // minLines 999999// maxLines ), /** * Display his scrolled, vertically, has menu bar */ SCROLLEDV( Rendering.APPLET, // rendering using Applet true, // bar true, // v false, // h 245, // minwidth 60, // minheight 800, // maxwidth 600, // maxheight 1, // minLines 999999// maxLines ), /** * Display his scrolled, both horizontally and vertically, has menu bar */ SCROLLEDHV( Rendering.APPLET, // rendering using Applet true, // bar true, // v true, // h 245, // minwidth 75, // minheight 800, // maxwidth 600, // maxheight 1, // minLines 999999// maxLines ); /** * true if want extra debugging output */ private static final boolean DEBUGGING = false; /** * render as INLINE, IFRAME or APPLET. */ private final Rendering rendering; /** * true if this sort of display has a bar */ private final boolean hasBar; /** * true if this sort of display has horizontal scroll bars for sliding left and right. */ private final boolean hasHScroll; /** * true if this sort of display has vertical scroll bars for sliding up and down. */ private final boolean hasVScroll; /** * The maximum height we allow the entire Applet to be with this sort of Display. */ private final int maxHeight; /** * The maximum number of lines in snippet to use this technique with. */ private final int maxLines; /** * the maximum width we allow the entire Applet to be with this sort of display. */ private final int maxWidth; /** * The minimum height we allow the entire Applet to be with this sort of Display. */ private final int minHeight; /** * The minimum number lines in snippet to use this technique. */ private final int minLines; /** * the minimum width we allow the entire Applet to be with this sort of display. */ private final int minWidth; /** * Constructor * * @param rendering render as INLINE, IFRAME or APPLET. * @param hasBar does this have a menu bar, line numbers and download controls at the top? * @param hasVScroll true if this enum type has vertical scroll bar * @param hasHScroll true if this enum type has horizontal scroll bar * @param minWidth minimum width in pixels of the total display including everything. This limit only applies if * we render in this style. * @param minHeight minimum height in pixels of the total display including everything. This limit only applies if * we render in this style. * @param maxWidth maximum width in pixels of the total display including everything. This limit only applies if * we render in this style. * @param maxHeight maximum height in pixels of the total display including everything. This limit only applies if * we render in this style. * @param minLines the minimum number lines in snippet to use this technique * @param maxLines the maximum number of lines in snippet to use this technique with. */ @SuppressWarnings( { "SameParameterValue" } ) WaysToRender( Rendering rendering, boolean hasBar, boolean hasVScroll, boolean hasHScroll, int minWidth, int minHeight, int maxWidth, int maxHeight, int minLines, int maxLines ) { this.rendering = rendering; this.hasBar = hasBar; this.hasVScroll = hasVScroll; this.hasHScroll = hasHScroll; this.minWidth = minWidth; this.minHeight = minHeight; this.maxWidth = maxWidth; this.maxHeight = maxHeight; this.minLines = minLines; this.maxLines = maxLines; } /** * find the best packaging to deal with a display of a given raw size. JPrep macro uses this to decide how to render * a given snippet. * * @param footprint a token display we are deciding how to render. It must have had calcPayLoad already called on * it. * @param maxWidth the maximum width allowed in pixels, usually comes from the macro JDisplay tag or an overall * limit on how much space any display should take, no matter how it is rendered. * @param maxHeight the maximum width allowed in pixels, usually comes from the macro JDisplay tag or an overall * limit on how much space any display should take, no matter how it is rendered. * * @return Footprint with actualAppletSize computed, the best way to render this Applet. */ public static Footprint bestFit( Footprint footprint, int maxWidth, int maxHeight ) { // try in order till find one that fits. Most preferable come first. for ( WaysToRender r : values() ) { // rough decision based on size of snippet int lines = footprint.totalLines; if ( r.minLines <= lines && lines <= r.maxLines ) { footprint.calcActualAppletFootPrint( r.rendering, r.hasBar, r.hasBar /* line numbers */, r.hasHScroll, r.hasVScroll, r.minWidth, r.minHeight, min( r.maxWidth, maxWidth ), min( r.maxHeight, maxHeight ), Geometry.SAFETY_FACTOR ); if ( footprint.viewportWidth > 0 ) { try { footprint.wayRendered = r.toString(); return ( Footprint ) footprint.clone(); } catch ( CloneNotSupportedException e ) { err.println( e.getMessage() ); System.exit( 1 ); } } } // end if } // end for throw new IllegalArgumentException( "com.mindprod.jdisplayaux.WaysToRender unable to find a way to do JDisplay." ); } }