/* * [Quilt.java] * * Summary: Generate the for grid of values like a quilt, with the entries sorted by columns. * * 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.common18.ST; import com.mindprod.comparators.HTMLComparator; import com.mindprod.fastcat.FastCat; import java.util.Arrays; import static java.lang.System.*; /** * Generate the for grid of values like a quilt, with the entries sorted by columns. * * @author Roedy Green, Canadian Mind Products * @version 1.8 2009-02-06 include go package in ZIP bundle. * @see QuiltPair * @since 2009 */ public final class Quilt extends Macro { /** * how to use the macro */ private static final String USAGE = "\nQuilt macro needs {size} [-byrows][-bycols][-sorted][-asis] {tableClass} {value} {value} ..."; // methods /** * guts to Generate the table for a quilt * * @param tableClass CSS final class of the table we generate * @param cols how many columns to generate. * @param cells cells to render * @param byCols true quilt ordering in columns like a phone book * * @return expanded explanation */ private static String expand( String tableClass, int cols, String[] cells, boolean byCols ) { // calc covered quotient final int rows = ( cells.length + cols - 1 ) / cols; // if there are not enough elements to fill the columns, // reduce the number of cols. cols = ( cells.length + rows - 1 ) / rows; // out.println( "rows:" + rows + " cols:" + cols ); final FastCat sb = new FastCat( 16 + rows * 2 + rows * cols * 3 ); sb.append( "\n
" ); final int k; if ( byCols ) { k = j * rows + i; } else { k = i * cols + j; } // out.println("i:" + i + " j:"+j + " k:" +k ); if ( k < cells.length ) { sb.append( cells[ k ] ); } else { // sb.append( " " ); // leave cell empty, renders as pale rectangle rather than // border button } sb.append( " | \n" ); } sb.append( "