import java.io.*; public class ImagePageGenerator { private String title; private String sourceDirectory; private String eoln; public ImagePageGenerator( String title, String directory ) { this.title = title; sourceDirectory = directory; eoln = System.getProperty( "line.separator" ); } public void writePage() { String fullname = sourceDirectory + "index.html"; try { BufferedWriter output = new BufferedWriter( new FileWriter(fullname) ); this.writePreamble( output ); this.writeHeader( output ); this.writeBody( output ); this.writePostamble( output ); output.close(); } catch (IOException ex) { System.out.println( "An error occurred writing the file " + fullname ); } } // ----- standard helpers private void writePreamble( BufferedWriter output ) throws IOException { output.write( "" ); output.newLine(); output.write( "" ); output.newLine(); } private void writeHeader( BufferedWriter output ) throws IOException { output.write( "
" ); output.newLine(); output.write( "Filename: " + name + "" + "
" + eoln; } } output.write( body ); } public void createThumbnails( String sourceDirectory ) { File directory = new File( sourceDirectory ); String[] filenames = directory.list(); String name; Picture p; for (int i = 0; i < filenames.length; i++) { name = filenames[i]; if ( name.endsWith(".jpg") ) { p = new Picture( sourceDirectory + name ); while ( p.getPixels().length > 40000 ) p= p.reduce(); p.write( sourceDirectory + "thumb-" + name ); } } } }