Made DitheringMethod a top-level enum and started using it from UniformPaletteQuantizerDialog (removing more constant ints).
1.1 --- a/net/sourceforge/jiu/gui/awt/AwtOperationProcessor.java Sat Aug 08 22:35:08 2009 +0200
1.2 +++ b/net/sourceforge/jiu/gui/awt/AwtOperationProcessor.java Sat Aug 08 22:54:09 2009 +0200
1.3 @@ -24,7 +24,6 @@
1.4 import net.sourceforge.jiu.color.reduction.*;
1.5 import net.sourceforge.jiu.gui.awt.dialogs.*;
1.6 import net.sourceforge.jiu.gui.awt.dialogs.MapToArbitraryPaletteDialog.PaletteType;
1.7 -import net.sourceforge.jiu.gui.awt.dialogs.ReduceGrayscaleDialog.DitheringMethod;
1.8 import net.sourceforge.jiu.codecs.*;
1.9 import net.sourceforge.jiu.data.*;
1.10 import net.sourceforge.jiu.filters.*;
1.11 @@ -676,21 +675,21 @@
1.12 process(red);
1.13 }
1.14
1.15 - private ErrorDiffusionType convertUniformToErrorDiffusion(int utype)
1.16 + private ErrorDiffusionType convertUniformToErrorDiffusion(DitheringMethod method)
1.17 {
1.18 - switch(utype)
1.19 + switch(method)
1.20 {
1.21 - case(UniformPaletteQuantizerDialog.TYPE_FLOYD_STEINBERG_ERROR_DIFFUSION):
1.22 + case FLOYD_STEINBERG_ERROR_DIFFUSION:
1.23 return ErrorDiffusionType.FLOYD_STEINBERG;
1.24 - case(UniformPaletteQuantizerDialog.TYPE_BURKES_ERROR_DIFFUSION):
1.25 + case BURKES_ERROR_DIFFUSION:
1.26 return ErrorDiffusionType.BURKES;
1.27 - case(UniformPaletteQuantizerDialog.TYPE_STUCKI_ERROR_DIFFUSION):
1.28 + case STUCKI_ERROR_DIFFUSION:
1.29 return ErrorDiffusionType.STUCKI;
1.30 - case(UniformPaletteQuantizerDialog.TYPE_SIERRA_ERROR_DIFFUSION):
1.31 + case SIERRA_ERROR_DIFFUSION:
1.32 return ErrorDiffusionType.SIERRA;
1.33 - case(UniformPaletteQuantizerDialog.TYPE_JARVIS_JUDICE_NINKE_ERROR_DIFFUSION):
1.34 + case JARVIS_JUDICE_NINKE_ERROR_DIFFUSION:
1.35 return ErrorDiffusionType.JARVIS_JUDICE_NINKE;
1.36 - case(UniformPaletteQuantizerDialog.TYPE_STEVENSON_ARCE_ERROR_DIFFUSION):
1.37 + case STEVENSON_ARCE_ERROR_DIFFUSION:
1.38 return ErrorDiffusionType.STEVENSON_ARCE;
1.39 default:
1.40 return null;
1.41 @@ -702,7 +701,7 @@
1.42 EditorState state = getEditorState();
1.43 Strings strings = state.getStrings();
1.44 UniformPaletteQuantizerDialog upqd = new UniformPaletteQuantizerDialog
1.45 - (frame, strings, 3, 3, 2, UniformPaletteQuantizerDialog.TYPE_FLOYD_STEINBERG_ERROR_DIFFUSION);
1.46 + (frame, strings, 3, 3, 2, DitheringMethod.FLOYD_STEINBERG_ERROR_DIFFUSION);
1.47 upqd.setVisible(true);
1.48 if (!upqd.hasPressedOk())
1.49 {
1.50 @@ -714,25 +713,25 @@
1.51 int sum = redBits + greenBits + blueBits;
1.52 switch (upqd.getDitheringMethod())
1.53 {
1.54 - case(UniformPaletteQuantizerDialog.TYPE_DITHERING_NONE):
1.55 + case NONE:
1.56 {
1.57 UniformPaletteQuantizer upq = new UniformPaletteQuantizer(redBits, greenBits, blueBits);
1.58 process(upq);
1.59 return;
1.60 }
1.61 - case(UniformPaletteQuantizerDialog.TYPE_ORDERED_DITHERING):
1.62 + case ORDERED:
1.63 {
1.64 OrderedDither od = new OrderedDither();
1.65 od.setRgbBits(redBits, greenBits, blueBits);
1.66 process(od);
1.67 return;
1.68 }
1.69 - case(UniformPaletteQuantizerDialog.TYPE_FLOYD_STEINBERG_ERROR_DIFFUSION):
1.70 - case(UniformPaletteQuantizerDialog.TYPE_BURKES_ERROR_DIFFUSION):
1.71 - case(UniformPaletteQuantizerDialog.TYPE_STUCKI_ERROR_DIFFUSION):
1.72 - case(UniformPaletteQuantizerDialog.TYPE_SIERRA_ERROR_DIFFUSION):
1.73 - case(UniformPaletteQuantizerDialog.TYPE_JARVIS_JUDICE_NINKE_ERROR_DIFFUSION):
1.74 - case(UniformPaletteQuantizerDialog.TYPE_STEVENSON_ARCE_ERROR_DIFFUSION):
1.75 + case FLOYD_STEINBERG_ERROR_DIFFUSION:
1.76 + case BURKES_ERROR_DIFFUSION:
1.77 + case STUCKI_ERROR_DIFFUSION:
1.78 + case SIERRA_ERROR_DIFFUSION:
1.79 + case JARVIS_JUDICE_NINKE_ERROR_DIFFUSION:
1.80 + case STEVENSON_ARCE_ERROR_DIFFUSION:
1.81 {
1.82 ErrorDiffusionDithering ed = new ErrorDiffusionDithering();
1.83 ed.setTemplateType(convertUniformToErrorDiffusion(upqd.getDitheringMethod()));
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/net/sourceforge/jiu/gui/awt/DitheringMethod.java Sat Aug 08 22:54:09 2009 +0200
2.3 @@ -0,0 +1,59 @@
2.4 +/*
2.5 + * Copyright (C) 2009 Knut Arild Erstad
2.6 + *
2.7 + * This file is part of JIU, the Java Imaging Utilities.
2.8 + *
2.9 + * JIU is free software; you can redistribute it and/or modify
2.10 + * it under the terms of the GNU General Public License version 2,
2.11 + * as published by the Free Software Foundation.
2.12 + *
2.13 + * Contributions by Knut Arild Erstad can be redistributed and/or
2.14 + * modified under GPL 2 or any later versions.
2.15 + *
2.16 + * JIU is distributed in the hope that it will be useful,
2.17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
2.18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2.19 + * GNU General Public License for more details.
2.20 + *
2.21 + * You should have received a copy of the GNU General Public License
2.22 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
2.23 + */
2.24 +package net.sourceforge.jiu.gui.awt;
2.25 +
2.26 +import net.sourceforge.jiu.apps.StringIndexConstants;
2.27 +import net.sourceforge.jiu.apps.Strings;
2.28 +
2.29 +/**
2.30 + * Enumerates the possible dithering methods and their string index values
2.31 + * (used by several dialogs).
2.32 + *
2.33 + * @author Marco Schmidt
2.34 + * @author Knut Arild Erstad
2.35 + */
2.36 +public enum DitheringMethod
2.37 +{
2.38 + NONE (Strings.DITHERING_NONE),
2.39 + ORDERED (Strings.ORDERED_DITHERING),
2.40 + FLOYD_STEINBERG_ERROR_DIFFUSION (Strings.FLOYD_STEINBERG_ERROR_DIFFUSION),
2.41 + STUCKI_ERROR_DIFFUSION (Strings.STUCKI_ERROR_DIFFUSION),
2.42 + BURKES_ERROR_DIFFUSION (Strings.BURKES_ERROR_DIFFUSION),
2.43 + SIERRA_ERROR_DIFFUSION (Strings.SIERRA_ERROR_DIFFUSION),
2.44 + JARVIS_JUDICE_NINKE_ERROR_DIFFUSION (Strings.JARVIS_JUDICE_NINKE_ERROR_DIFFUSION),
2.45 + STEVENSON_ARCE_ERROR_DIFFUSION (Strings.STEVENSON_ARCE_ERROR_DIFFUSION);
2.46 +
2.47 + private int stringConstant;
2.48 +
2.49 + private DitheringMethod(int stringConstant)
2.50 + {
2.51 + this.stringConstant = stringConstant;
2.52 + }
2.53 +
2.54 + /**
2.55 + * Get a string resource index which describes the enum value.
2.56 + * @return a {@link StringIndexConstants} value.
2.57 + */
2.58 + public int getStringConstant()
2.59 + {
2.60 + return stringConstant;
2.61 + }
2.62 +}
2.63 \ No newline at end of file
3.1 --- a/net/sourceforge/jiu/gui/awt/dialogs/ReduceGrayscaleDialog.java Sat Aug 08 22:35:08 2009 +0200
3.2 +++ b/net/sourceforge/jiu/gui/awt/dialogs/ReduceGrayscaleDialog.java Sat Aug 08 22:54:09 2009 +0200
3.3 @@ -24,8 +24,8 @@
3.4 import java.awt.event.AdjustmentEvent;
3.5 import java.awt.event.AdjustmentListener;
3.6
3.7 -import net.sourceforge.jiu.apps.StringIndexConstants;
3.8 import net.sourceforge.jiu.apps.Strings;
3.9 +import net.sourceforge.jiu.gui.awt.DitheringMethod;
3.10 import net.sourceforge.jiu.util.EnumHelper;
3.11
3.12 /**
3.13 @@ -34,37 +34,6 @@
3.14 */
3.15 public class ReduceGrayscaleDialog extends Dialog implements ActionListener, AdjustmentListener
3.16 {
3.17 - /**
3.18 - * Enumerates the possible dithering methods.
3.19 - */
3.20 - public enum DitheringMethod
3.21 - {
3.22 - NONE (Strings.DITHERING_NONE),
3.23 - ORDERED (Strings.ORDERED_DITHERING),
3.24 - FLOYD_STEINBERG_ERROR_DIFFUSION (Strings.FLOYD_STEINBERG_ERROR_DIFFUSION),
3.25 - STUCKI_ERROR_DIFFUSION (Strings.STUCKI_ERROR_DIFFUSION),
3.26 - BURKES_ERROR_DIFFUSION (Strings.BURKES_ERROR_DIFFUSION),
3.27 - SIERRA_ERROR_DIFFUSION (Strings.SIERRA_ERROR_DIFFUSION),
3.28 - JARVIS_JUDICE_NINKE_ERROR_DIFFUSION (Strings.JARVIS_JUDICE_NINKE_ERROR_DIFFUSION),
3.29 - STEVENSON_ARCE_ERROR_DIFFUSION (Strings.STEVENSON_ARCE_ERROR_DIFFUSION);
3.30 -
3.31 - private int stringConstant;
3.32 -
3.33 - private DitheringMethod(int stringConstant)
3.34 - {
3.35 - this.stringConstant = stringConstant;
3.36 - }
3.37 -
3.38 - /**
3.39 - * Get a string resource index which describes the enum value.
3.40 - * @return a {@link StringIndexConstants} value.
3.41 - */
3.42 - public int getStringConstant()
3.43 - {
3.44 - return stringConstant;
3.45 - }
3.46 - }
3.47 -
3.48 private Strings strings;
3.49 private Button ok;
3.50 private Button cancel;
4.1 --- a/net/sourceforge/jiu/gui/awt/dialogs/UniformPaletteQuantizerDialog.java Sat Aug 08 22:35:08 2009 +0200
4.2 +++ b/net/sourceforge/jiu/gui/awt/dialogs/UniformPaletteQuantizerDialog.java Sat Aug 08 22:54:09 2009 +0200
4.3 @@ -26,6 +26,8 @@
4.4 import java.awt.event.ItemEvent;
4.5 import java.awt.event.ItemListener;
4.6 import net.sourceforge.jiu.apps.Strings;
4.7 +import net.sourceforge.jiu.gui.awt.DitheringMethod;
4.8 +import net.sourceforge.jiu.util.EnumHelper;
4.9
4.10 /**
4.11 * An AWT dialog to enter the parameters for a uniform palette color quantization operation.
4.12 @@ -33,37 +35,6 @@
4.13 */
4.14 public class UniformPaletteQuantizerDialog extends Dialog implements ActionListener, AdjustmentListener, ItemListener
4.15 {
4.16 - public static final int TYPE_DITHERING_NONE = 0;
4.17 - public static final int TYPE_ORDERED_DITHERING = 1;
4.18 - public static final int TYPE_FLOYD_STEINBERG_ERROR_DIFFUSION = 2;
4.19 - public static final int TYPE_STUCKI_ERROR_DIFFUSION = 3;
4.20 - public static final int TYPE_BURKES_ERROR_DIFFUSION = 4;
4.21 - public static final int TYPE_SIERRA_ERROR_DIFFUSION = 5;
4.22 - public static final int TYPE_JARVIS_JUDICE_NINKE_ERROR_DIFFUSION = 6;
4.23 - public static final int TYPE_STEVENSON_ARCE_ERROR_DIFFUSION = 7;
4.24 - public final int[][] DITHERING_METHODS =
4.25 - {
4.26 - {
4.27 - TYPE_DITHERING_NONE,
4.28 - TYPE_ORDERED_DITHERING,
4.29 - TYPE_FLOYD_STEINBERG_ERROR_DIFFUSION,
4.30 - TYPE_STUCKI_ERROR_DIFFUSION,
4.31 - TYPE_BURKES_ERROR_DIFFUSION,
4.32 - TYPE_SIERRA_ERROR_DIFFUSION,
4.33 - TYPE_JARVIS_JUDICE_NINKE_ERROR_DIFFUSION,
4.34 - TYPE_STEVENSON_ARCE_ERROR_DIFFUSION
4.35 - },
4.36 - {
4.37 - Strings.DITHERING_NONE,
4.38 - Strings.ORDERED_DITHERING,
4.39 - Strings.FLOYD_STEINBERG_ERROR_DIFFUSION,
4.40 - Strings.STUCKI_ERROR_DIFFUSION,
4.41 - Strings.BURKES_ERROR_DIFFUSION,
4.42 - Strings.SIERRA_ERROR_DIFFUSION,
4.43 - Strings.JARVIS_JUDICE_NINKE_ERROR_DIFFUSION,
4.44 - Strings.STEVENSON_ARCE_ERROR_DIFFUSION
4.45 - }
4.46 - };
4.47 private Strings strings;
4.48 private Button ok;
4.49 private Button cancel;
4.50 @@ -88,7 +59,7 @@
4.51 * @param ditheringMethodSelection initial selection for dithering method
4.52 */
4.53 public UniformPaletteQuantizerDialog(Frame owner, Strings strings, int redBits,
4.54 - int greenBits, int blueBits, int ditheringMethodSelection)
4.55 + int greenBits, int blueBits, DitheringMethod ditheringMethodSelection)
4.56 {
4.57 super(owner, strings.get(Strings.UNIFORM_PALETTE_COLOR_QUANTIZATION), true);
4.58 pressedOk = false;
4.59 @@ -121,12 +92,12 @@
4.60
4.61 panel.add(new Label(strings.get(Strings.DITHERING_METHOD)));
4.62 ditheringMethod = new Choice();
4.63 - for (int i = 0; i < DITHERING_METHODS[0].length; i++)
4.64 + for (DitheringMethod method: DitheringMethod.values())
4.65 {
4.66 - ditheringMethod.add(strings.get(DITHERING_METHODS[1][i]));
4.67 - if (ditheringMethodSelection == i)
4.68 + ditheringMethod.add(strings.get(method.getStringConstant()));
4.69 + if (method == ditheringMethodSelection)
4.70 {
4.71 - ditheringMethod.select(i);
4.72 + ditheringMethod.select(method.ordinal());
4.73 }
4.74 }
4.75 ditheringMethod.addItemListener(this);
4.76 @@ -191,9 +162,9 @@
4.77 return getValue(numColorsField);
4.78 }*/
4.79
4.80 - public int getDitheringMethod()
4.81 + public DitheringMethod getDitheringMethod()
4.82 {
4.83 - return DITHERING_METHODS[0][ditheringMethod.getSelectedIndex()];
4.84 + return EnumHelper.fromOrdinal(DitheringMethod.values(), ditheringMethod.getSelectedIndex());
4.85 }
4.86
4.87 public int getBlueBits()
4.88 @@ -222,7 +193,7 @@
4.89 int g = getGreenBits();
4.90 int b = getBlueBits();
4.91 int sum = r + g + b;
4.92 - if (getDitheringMethod() == TYPE_DITHERING_NONE)
4.93 + if (getDitheringMethod() == DitheringMethod.NONE)
4.94 {
4.95 return (sum < 9);
4.96 }