/************************************************************************** /* This class creates an image-gallery from a list of images passed in as /* commandline-arguments. /* /* Copyright (c) 2004 by Bernhard Bablok (mail@bablokb.de) /* /* This program is free software; you can redistribute it and/or modify /* it under the terms of the GNU General Public License as published /* by the Free Software Foundation; either version 2 of the License or /* (at your option) any later version. /* /* This program is distributed in the hope that it will be useful, but /* WITHOUT ANY WARRANTY; without even the implied warranty of /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the /* GNU General Public License for more details. /* /* You should have received a copy of the GNU General Public License /* along with this program; see the file COPYING. If not, write to /* the Free Software Foundation Inc., 59 Temple Place - Suite 330, /* Boston, MA 02111-1307 USA /**************************************************************************/ import java.io.*; import java.util.*; import com.lowagie.text.*; import com.lowagie.text.pdf.*; /** This class creates an image-gallery from a list of images passed in as commandline-arguments. @version $Revision: 1.11 $ @author $Author: bablokb $ */ public class Gallery { /** Array of image-names. */ private static String[] iImageName; /** Name of property file. */ private String iPropFile; /** Property object for titles etc. */ private Properties iProps = new Properties(); /** Standard color. */ private static final java.awt.Color iColor = java.awt.Color.WHITE; /** Standard font for all text. */ private static final Font iFont = FontFactory .getFont(FontFactory.HELVETICA,20,Font.BOLD,iColor); ////////////////////////////////////////////////////////////////////////////// public static void main(String[] args) { try { // setup environment Gallery gallery = new Gallery(); String galleryName = gallery.parseArguments(args); gallery.loadProperties(); // prepare document and writer Document document = gallery.getDocument(); gallery.getWriter(document,galleryName); gallery.addMetaInfo(document); document.open(); // process individual images for (int i=0;i height) ratio = 80/width; else ratio = 80/height; img.setAlignment(Image.MIDDLE); img.scalePercent(ratio*100); indexTable.addCell(new Cell(img)); // set image description File file = new File(iImageName[i]); String imageTitle = iProps.getProperty(file.getName(),file.getName()); Anchor title = new Anchor(imageTitle,iFont); title.setReference("#"+file.getName()); indexTable.addCell(new Cell(title)); } doc.add(indexTable); } ////////////////////////////////////////////////////////////////////////////// /** Parse commandline-arguments. Must be in the form
-o outputfile inputfile [ ... ]
     
@param args The original commandline arguments @return The name of the output-file */ private String parseArguments(String[] args) { int start = 2; if (args.length < 3) usage(); else if (!args[0].equals("-o")) usage(); if (args[2].equals("-p")) { if (args.length < 5) usage(); iPropFile = args[3]; start = 4; } iImageName = new String[args.length - start]; System.arraycopy(args,start,iImageName,0,iImageName.length); return args[1]; } ////////////////////////////////////////////////////////////////////////////// /** Display usage information and exit. */ private void usage() { System.out.println("usage: java " + Gallery.class.getName() + " -o outputfile [-p props] inputfile [...]"); System.exit(3); } ///////////////////////////////////////////////////////////////////////////// /** Load properties file. */ private void loadProperties() throws Exception { if (iPropFile == null) return; FileInputStream stream = new FileInputStream(iPropFile); iProps.load(stream); stream.close(); } }