// // InitPattern.java // Anneal // // Created by sw on Thu Sep 12 2002. // Copyright (c) 2001 __MyCompanyName__. All rights reserved. // package net.tiac.home.sw.anneal; import java.lang.Integer; import java.awt.*; import java.awt.event.*; import java.applet.Applet; // To use an InitPattern, first call setMaxDimension() to tell it // the area it can take advantage of, then call arrayDimension() to // find out the size of array you need, and call cell() to tell // whether each cell should start on or off. // Each of the anonymous subclasses of InitPattern defines // a name() method that returns a fixed string for a menu. // The reason the max dimensions aren't set when the object is // created is that the InitPatterns need to be created // to populate a menu, so that the width of their names can // be used to determine the layout, including the max dimension! // The initValues choice in the ControlPanel uses the // InitPatternPlethora class to get an array of // InitPatterns. class InitPattern { protected Dimension maxDimension; String myName; // Default constructor: public InitPattern( String name ) { this.myName = name; this.maxDimension = null; } // Shared methods: public String name( ) { return( myName ); } public void setMaxDimension( Dimension maxDimension ) { this.maxDimension = maxDimension; } protected Dimension dimensionClosestMultOf( int width, int height, int xm, int ym ) { return new Dimension( (width/xm) * xm, (height/ym) * ym ); } protected Dimension dimensionClosestMultOf( Dimension maxDimension, int xm, int ym ) { return dimensionClosestMultOf( maxDimension.width, maxDimension.height, xm, ym ); } protected Dimension dimensionClosestMultOf( int xm, int ym ) { return dimensionClosestMultOf( this.maxDimension, xm, ym ); } // Default arrayDimension is the same as the maxDimension: public Dimension arrayDimension( ) { return( maxDimension ); } // "Abstract" methods: // Oops, sorry, my compiler can't handle anonymous classes based on // abstract classes. BUT, for users of objects declared to be of type // InitPattern to use the following methods, they have to be // declared here! public boolean cell( int x, int y ) { throw( new Error( "Used a method that's supposed to be overridden." ) ); } }