SourceForge: jiu/jiu: changeset 49:5ea3208526f8
MapToArbitraryPaletteDialog: replaced PALETTE constants with a PaletteType enum. java-1.5
authorKnut Arild Erstad <knutae@gmail.com>
Sat Aug 08 22:17:16 2009 +0200 (3 months ago)
branchjava-1.5
changeset 495ea3208526f8
parent 48abe6a803a32c
child 50306014bbfae6
MapToArbitraryPaletteDialog: replaced PALETTE constants with a PaletteType enum.
net/sourceforge/jiu/gui/awt/AwtOperationProcessor.java
net/sourceforge/jiu/gui/awt/dialogs/MapToArbitraryPaletteDialog.java
     1.1 --- a/net/sourceforge/jiu/gui/awt/AwtOperationProcessor.java	Sat Aug 08 21:26:33 2009 +0200
     1.2 +++ b/net/sourceforge/jiu/gui/awt/AwtOperationProcessor.java	Sat Aug 08 22:17:16 2009 +0200
     1.3 @@ -23,6 +23,7 @@
     1.4  import net.sourceforge.jiu.color.quantization.MedianCutQuantizer.RepresentativeColorMethod;
     1.5  import net.sourceforge.jiu.color.reduction.*;
     1.6  import net.sourceforge.jiu.gui.awt.dialogs.*;
     1.7 +import net.sourceforge.jiu.gui.awt.dialogs.MapToArbitraryPaletteDialog.PaletteType;
     1.8  import net.sourceforge.jiu.codecs.*;
     1.9  import net.sourceforge.jiu.data.*;
    1.10  import net.sourceforge.jiu.filters.*;
    1.11 @@ -758,8 +759,8 @@
    1.12  		{
    1.13  			return;
    1.14  		}
    1.15 -		int paletteType = d.getPaletteType();
    1.16 -		if (paletteType < 0)
    1.17 +		PaletteType paletteType = d.getPaletteType();
    1.18 +		if (paletteType == null)
    1.19  		{
    1.20  			return;
    1.21  		}
    1.22 @@ -767,7 +768,7 @@
    1.23  		Palette palette;
    1.24  		switch(paletteType)
    1.25  		{
    1.26 -			case(MapToArbitraryPaletteDialog.PALETTE_FILE):
    1.27 +			case FILE:
    1.28  			{
    1.29  				String name = getUserFileName(null, StringIndexConstants.LOAD_PALETTE, FileDialog.LOAD);
    1.30  				if (name == null)
    1.31 @@ -778,27 +779,27 @@
    1.32  				palette = PaletteSerialization.load(file);
    1.33  				break;
    1.34  			}
    1.35 -			case(MapToArbitraryPaletteDialog.PALETTE_WEBSAFE):
    1.36 +			case WEBSAFE:
    1.37  			{
    1.38  				palette = WebsafePaletteCreator.create();
    1.39  				break;
    1.40  			}
    1.41 -			case(MapToArbitraryPaletteDialog.PALETTE_PALM_256_COLORS):
    1.42 +			case PALM_256_COLORS:
    1.43  			{
    1.44  				palette = PalmCodec.createSystem8BitPalette();
    1.45  				break;
    1.46  			}
    1.47 -			case(MapToArbitraryPaletteDialog.PALETTE_PALM_16_COLORS):
    1.48 +			case PALM_16_COLORS:
    1.49  			{
    1.50  				palette = PalmCodec.createSystem4BitColorPalette();
    1.51  				break;
    1.52  			}
    1.53 -			case(MapToArbitraryPaletteDialog.PALETTE_PALM_16_GRAY):
    1.54 +			case PALM_16_GRAY:
    1.55  			{
    1.56  				palette = PalmCodec.createSystem4BitGrayscalePalette();
    1.57  				break;
    1.58  			}
    1.59 -			case(MapToArbitraryPaletteDialog.PALETTE_PALM_4_GRAY):
    1.60 +			case PALM_4_GRAY:
    1.61  			{
    1.62  				palette = PalmCodec.createSystem2BitGrayscalePalette();
    1.63  				break;
     2.1 --- a/net/sourceforge/jiu/gui/awt/dialogs/MapToArbitraryPaletteDialog.java	Sat Aug 08 21:26:33 2009 +0200
     2.2 +++ b/net/sourceforge/jiu/gui/awt/dialogs/MapToArbitraryPaletteDialog.java	Sat Aug 08 22:17:16 2009 +0200
     2.3 @@ -34,22 +34,27 @@
     2.4  public class MapToArbitraryPaletteDialog extends Dialog implements
     2.5  	ActionListener
     2.6  {
     2.7 -	public static final int PALETTE_FILE = 0;
     2.8 -	public static final int PALETTE_WEBSAFE = 1;
     2.9 -	public static final int PALETTE_PALM_256_COLORS = 2;
    2.10 -	public static final int PALETTE_PALM_16_COLORS = 3;
    2.11 -	public static final int PALETTE_PALM_16_GRAY = 4;
    2.12 -	public static final int PALETTE_PALM_4_GRAY = 5;
    2.13 -	public static final int NUM_PALETTE_TYPES = 6;
    2.14 -	private static final int[] PALETTE_STRING_CONSTANTS =
    2.15 +	public enum PaletteType
    2.16  	{
    2.17 -		Strings.PALETTE_FROM_FILE,
    2.18 -		Strings.WEBSAFE_PALETTE,
    2.19 -		Strings.PALETTE_PALM_256_COLORS,
    2.20 -		Strings.PALETTE_PALM_16_COLORS,
    2.21 -		Strings.PALETTE_PALM_16_GRAY,
    2.22 -		Strings.PALETTE_PALM_4_GRAY,
    2.23 -	};
    2.24 +		FILE (Strings.PALETTE_FROM_FILE),
    2.25 +		WEBSAFE (Strings.WEBSAFE_PALETTE),
    2.26 +		PALM_256_COLORS (Strings.PALETTE_PALM_256_COLORS),
    2.27 +		PALM_16_COLORS (Strings.PALETTE_PALM_16_COLORS),
    2.28 +		PALM_16_GRAY (Strings.PALETTE_PALM_16_GRAY),
    2.29 +		PALM_4_GRAY (Strings.PALETTE_PALM_4_GRAY);
    2.30 +		
    2.31 +		private int stringConstant;
    2.32 +		
    2.33 +		private PaletteType(int stringConstant)
    2.34 +		{
    2.35 +			this.stringConstant = stringConstant;
    2.36 +		}
    2.37 +		
    2.38 +		public int getStringConstant()
    2.39 +		{
    2.40 +			return stringConstant;
    2.41 +		}
    2.42 +	}
    2.43  
    2.44  	private static final int[] DITHERING_STRING_CONSTANTS =
    2.45  	{
    2.46 @@ -91,11 +96,13 @@
    2.47  		// 1.2 radio buttons (CheckboxGroup) with palette type
    2.48  		panel = new Panel(new GridLayout(0, 1));
    2.49  		paletteType = new CheckboxGroup();
    2.50 -		checkboxes = new Checkbox[PALETTE_STRING_CONSTANTS.length];
    2.51 +		PaletteType[] paletteTypes = PaletteType.values();
    2.52 +		checkboxes = new Checkbox[paletteTypes.length];
    2.53  		boolean selected = true;
    2.54 -		for (int i = 0; i < NUM_PALETTE_TYPES; i++)
    2.55 +		for (int i = 0; i < paletteTypes.length; i++)
    2.56  		{
    2.57 -			checkboxes[i] = new Checkbox(strings.get(PALETTE_STRING_CONSTANTS[i]), paletteType, selected);
    2.58 +			checkboxes[i] = new Checkbox(strings.get(paletteTypes[i].getStringConstant()),
    2.59 +					paletteType, selected);
    2.60  			selected = false;
    2.61  			panel.add(checkboxes[i]);
    2.62  		}
    2.63 @@ -166,16 +173,16 @@
    2.64  	 * Return the palette type (one of the PALETTE_xyz constants of this class)
    2.65  	 * that is currently selected in the dialog.
    2.66  	 */
    2.67 -	public int getPaletteType()
    2.68 +	public PaletteType getPaletteType()
    2.69  	{
    2.70  		for (int i = 0; i < checkboxes.length; i++)
    2.71  		{
    2.72  			if (checkboxes[i].getState())
    2.73  			{
    2.74 -				return i;
    2.75 +				return EnumHelper.fromOrdinal(PaletteType.values(), i);
    2.76  			}
    2.77  		}
    2.78 -		return -1;
    2.79 +		return null;
    2.80  	}
    2.81  
    2.82  	/**