Package net.sourceforge.jiu.apps

# Class EditorState

java.lang.Object
net.sourceforge.jiu.apps.EditorState

All Implemented Interfaces:
  `MenuIndexConstants`

public class EditorState extends Object implements MenuIndexConstants
Represents the state of the editor, including image(s), modified flag, current file name and directories and more. This class must not know GUI-specific information like Frame or JFrame objects. These GUI classes (more precisely, the JIU classes that extend them) will have to know EditorState and update according to the information they retrieve from an EditorState object associated with them. EditorState is a pure data container.

Author:
  Marco Schmidt

## Field Summary

Fields
Modifier and Type
Field
Description
`private String`
`currentDirectory`
`private PixelImage`
`currentImage`
`static final int`
`DEFAULT_INTERPOLATION`
The default interpolation type, one of the three INTERPOLATION_xyz constants.
`static final int`
`DEFAULT_MAX_REDO_IMAGES`
The default number of redo steps possible.
`static final int`
`DEFAULT_MAX_UNDO_IMAGES`
The default number of undo steps possible.
`private String`
`fileName`
`private int`
`interpolation`
`static final int`
`INTERPOLATION_BICUBIC`
Integer constant for bicubic interpolation.
`static final int`
`INTERPOLATION_BILINEAR`
Integer constant for bilinear neighbor interpolation.
`static final int`
`INTERPOLATION_NEAREST_NEIGHBOR`
Integer constant for nearest neighbor interpolation.
`private Locale`
`locale`
`private int`
`maxRedoImages`
`private int`
`maxUndoImages`
`private boolean`
`modified`
`static final int`
`ORIGINAL_SIZE_ZOOM_INDEX`
The index into the `ZOOM_LEVELS` array that holds the original size zoom level (100 percent).
`private Vector`
`progressListeners`
`private Vector`
`redoImages`
`private Vector`
`redoModified`
`private String`
`startupImageName`
`private Strings`
`strings`
`private Vector`
`undoImages`
`private Vector`
`undoModified`
`static final int[]`
`ZOOM_LEVELS`
All allowed zoom levels, as percentage values in ascending order.
`private double`
`zoomFactorX`
`private double`
`zoomFactorY`
`private int`
`zoomIndex`
`private boolean`
`zoomToFit`

### Fields inherited from interface net.sourceforge.jiu.apps.MenuIndexConstants

`COLOR, COLOR_ADJUST, COLOR_ADJUST_BRIGHTNESS, COLOR_ADJUST_CONTRAST, COLOR_ADJUST_GAMMA, COLOR_ADJUST_HUESATURATIONVALUE, COLOR_CONVERTTOMINIMUMCOLORTYPE, COLOR_HISTOGRAM, COLOR_HISTOGRAM_COUNTCOLORSUSED, COLOR_HISTOGRAM_EQUALIZE, COLOR_HISTOGRAM_NORMALIZE, COLOR_HISTOGRAM_SAVECOOCCURRENCEFREQUENCYMATRIXAS, COLOR_HISTOGRAM_SAVECOOCCURRENCEMATRIXAS, COLOR_HISTOGRAM_SAVEHISTOGRAMAS, COLOR_HISTOGRAM_TEXTUREPROPERTIES, COLOR_INVERT, COLOR_PALETTE, COLOR_PALETTE_SAVEAS, COLOR_PROMOTE, COLOR_PROMOTE_PROMOTETOGRAY16, COLOR_PROMOTE_PROMOTETOGRAY8, COLOR_PROMOTE_PROMOTETOPALETTED, COLOR_PROMOTE_PROMOTETORGB24, COLOR_PROMOTE_PROMOTETORGB48, COLOR_REDUCE, COLOR_REDUCE_CONVERTTOGRAYSCALE, COLOR_REDUCE_MAPTOARBITRARYPALETTE, COLOR_REDUCE_MEDIANCUT, COLOR_REDUCE_OCTREE, COLOR_REDUCE_REDUCENUMBEROFSHADESOFGRAY, COLOR_REDUCE_REDUCETOBILEVELTHRESHOLD, COLOR_REDUCE_UNIFORMPALETTE, EDIT, EDIT_REDO, EDIT_UNDO, FILE, FILE_CLOSE, FILE_EXIT, FILE_IMAGE_1, FILE_OPEN, FILE_SAVEAS, FILE_SAVEAS_GIF, FILE_SAVEAS_PALM, FILE_SAVEAS_PBM, FILE_SAVEAS_PGM, FILE_SAVEAS_PNG, FILE_SAVEAS_PPM, FILE_SAVEAS_SUNRASTER, FILE_SAVEAS_WINDOWSBMP, FILTERS, FILTERS_BLUR, FILTERS_EDGEDETECTION, FILTERS_EMBOSS, FILTERS_HORIZONTALPREWITT, FILTERS_HORIZONTALSOBEL, FILTERS_LITHOGRAPH, FILTERS_MAXIMUM, FILTERS_MEAN, FILTERS_MEDIAN, FILTERS_MINIMUM, FILTERS_OIL, FILTERS_PSYCHEDELICDISTILLATION, FILTERS_SHARPEN, FILTERS_VERTICALPREWITT, FILTERS_VERTICALSOBEL, HELP, HELP_ABOUT, HELP_SYSTEMINFORMATION, NUM_CONSTANTS, TRANSFORMATIONS, TRANSFORMATIONS_CROP, TRANSFORMATIONS_FLIP, TRANSFORMATIONS_MIRROR, TRANSFORMATIONS_ROTATE180, TRANSFORMATIONS_ROTATELEFT90, TRANSFORMATIONS_ROTATERIGHT90, TRANSFORMATIONS_SCALE, TRANSFORMATIONS_SHEAR, VIEW, VIEW_INTERPOLATIONTYPE, VIEW_INTERPOLATIONTYPE_BICUBIC, VIEW_INTERPOLATIONTYPE_BILINEAR, VIEW_INTERPOLATIONTYPE_NEARESTNEIGHBOR, VIEW_SETORIGINALSIZE, VIEW_ZOOMIN, VIEW_ZOOMOUT`

## Constructor Summary

Constructors
Constructor
Description
`EditorState()`
Create new EditorState object and initialize its private fields to default values.

## Method Summary

Modifier and Type
Method
Description
`private void`
`addImageToRedo(PixelImage image, boolean modifiedState)`
`private void`
`addImageToUndo(PixelImage image, boolean modifiedState)`
`void`
`addProgressListener(ProgressListener pl)`
Adds the argument progress listener to the internal list of progress listeners to be notified by progress updates.
`boolean`
`canRedo()`
Returns if a redo operation is possible right now.
`boolean`
`canUndo()`
Returns if an undo operation is possible right now.
`void`
`clearRedo()`
`void`
`clearUndo()`
`void`
`ensureStringsAvailable()`
`String`
`getCurrentDirectory()`
Returns the current directory.
`String`
`getFileName()`
Returns the name of the file from which the current image was loaded.
`PixelImage`
`getImage()`
Returns the image object currently loaded.
`int`
`getInterpolation()`
Returns the current interpolation type, one of the INTERPOLATION_xyz constants.
`Locale`
`getLocale()`
Returns the Locale object currently used.
`boolean`
`getModified()`
Returns the current modified state (true if image was modified and not saved after modification, false otherwise).
`Vector`
`getProgressListeners()`
Returns the internal list of progress listeners.
`String`
`getStartupImageName()`
`Strings`
`getStrings()`
Returns the Strings object currently in use.
`double`
`getZoomFactorX()`
Returns the current zoom factor in horizontal direction.
`double`
`getZoomFactorY()`
Returns the current zoom factor in vertical direction.
`boolean`
`getZoomToFit()`
Returns if image display is currently set to "zoom to fit" Zoom to fit means that the image is always zoomed to fit exactly into the window.
`boolean`
`hasImage()`
Returns if this state encapsulates an image object.
`void`
`installProgressListeners(Operation op)`
Adds all ProgressListener objects from the internal list of listeners to the argument operation.
`boolean`
`isMaximumZoom()`
Returns if the image is displayed at maximum zoom level.
`boolean`
`isMinimumZoom()`
Returns if the image is displayed at minimum zoom level.
`boolean`
`isZoomOriginalSize()`
Returns if the current zoom level is set to original size (each image pixel is displayed as one pixel).
`void`
`redo()`
Perform a redo operation, restore the state before the last undo operation.
`void`
`resetZoomFactors()`
`void`
`setCurrentDirectory(String newCurrentDirectory)`
Sets a new current directory.
`void`
`setFileName(String newFileName)`
Sets a new file name.
`void`
`setImage(PixelImage image, boolean newModifiedState)`
Sets image and modified state to argument values.
`void`
`setInterpolation(int newInterpolation)`
Sets a new interpolation type to be used for display.
`void`
`setLocale(Locale newLocale)`
Defines a new Locale to be used.
`void`
`setStartupImageName(String name)`
`void`
`setStrings(String iso639Code)`
Set new Strings resource.
`void`
`setZoomFactors(double zoomX, double zoomY)`
Sets the zoom factors to the argument values.
`void`
`undo()`
Perform an undo step - the previous state will be set, the current state will be saved for a redo operation
`void`
`zoomIn()`
Increase the zoom level by one.
`void`
`zoomOut()`
Decrease the zoom level by one.
`void`
`zoomSetOriginalSize()`
Set the zoom level to 100 percent (1:1).

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### DEFAULT_MAX_UNDO_IMAGES

public static final int DEFAULT_MAX_UNDO_IMAGES
The default number of undo steps possible.

See Also:
  - Constant Field Values

### DEFAULT_MAX_REDO_IMAGES

public static final int DEFAULT_MAX_REDO_IMAGES
The default number of redo steps possible.

See Also:
  - Constant Field Values

### ZOOM_LEVELS

public static final int[] ZOOM_LEVELS
All allowed zoom levels, as percentage values in ascending order.

### ORIGINAL_SIZE_ZOOM_INDEX

public static final int ORIGINAL_SIZE_ZOOM_INDEX
The index into the `ZOOM_LEVELS` array that holds the original size zoom level (100 percent). So, ZOOM_LEVELS[ORIGINAL_SIZE_ZOOM_INDEX] must be equal to 100.

See Also:
  - Constant Field Values

### INTERPOLATION_NEAREST_NEIGHBOR

public static final int INTERPOLATION_NEAREST_NEIGHBOR
Integer constant for nearest neighbor interpolation. A fast but ugly method.

See Also:
  - Constant Field Values

### INTERPOLATION_BILINEAR

public static final int INTERPOLATION_BILINEAR
Integer constant for bilinear neighbor interpolation. A slow but nice method.

See Also:
  - Constant Field Values

### INTERPOLATION_BICUBIC

public static final int INTERPOLATION_BICUBIC
Integer constant for bicubic interpolation. A very slow method, but with the nicest output of the three supported interpolation types.

See Also:
  - Constant Field Values

### DEFAULT_INTERPOLATION

public static final int DEFAULT_INTERPOLATION
The default interpolation type, one of the three INTERPOLATION_xyz constants.

See Also:
  - Constant Field Values

### currentDirectory

private String currentDirectory

### fileName

private String fileName

### currentImage

private PixelImage currentImage

### interpolation

private int interpolation

### locale

private Locale locale

### maxRedoImages

private int maxRedoImages

### maxUndoImages

private int maxUndoImages

### modified

private boolean modified

### progressListeners

private Vector progressListeners

### redoImages

private Vector redoImages

### redoModified

private Vector redoModified

### startupImageName

private String startupImageName

### strings

private Strings strings

### undoImages

private Vector undoImages

### undoModified

private Vector undoModified

### zoomIndex

private int zoomIndex

### zoomFactorX

private double zoomFactorX

### zoomFactorY

private double zoomFactorY

### zoomToFit

private boolean zoomToFit

## Constructor Details

### EditorState

public EditorState()
Create new EditorState object and initialize its private fields to default values.

## Method Details

### addImageToRedo

private void addImageToRedo(PixelImage image, boolean modifiedState)

### addImageToUndo

private void addImageToUndo(PixelImage image, boolean modifiedState)

### addProgressListener

public void addProgressListener(ProgressListener pl)
Adds the argument progress listener to the internal list of progress listeners to be notified by progress updates.

Parameters:
  `pl` - object implementing ProgressListener to be added

### canRedo

public boolean canRedo()
Returns if a redo operation is possible right now.

### canUndo

public boolean canUndo()
Returns if an undo operation is possible right now.

### clearRedo

public void clearRedo()

### clearUndo

public void clearUndo()

### ensureStringsAvailable

public void ensureStringsAvailable()

### getCurrentDirectory

public String getCurrentDirectory()
Returns the current directory. This directory will be used when file dialogs are opened.

### getFileName

public String getFileName()
Returns the name of the file from which the current image was loaded.

### getImage

public PixelImage getImage()
Returns the image object currently loaded.

### getInterpolation

public int getInterpolation()
Returns the current interpolation type, one of the INTERPOLATION_xyz constants.

### getLocale

public Locale getLocale()
Returns the Locale object currently used.

### getModified

public boolean getModified()
Returns the current modified state (true if image was modified and not saved after modification, false otherwise).

### getProgressListeners

public Vector getProgressListeners()
Returns the internal list of progress listeners.

### getStartupImageName

public String getStartupImageName()

### getStrings

public Strings getStrings()
Returns the Strings object currently in use.

### getZoomFactorX

public double getZoomFactorX()
Returns the current zoom factor in horizontal direction. The value 1.0 means that the image is displayed at its original size. Anything smaller means that the image is scaled down, anything larger means that the image is scaled up. The value must not be smaller than or equal to 0.0.

Returns:
  zoom factor in horizontal direction
See Also:
  - `getZoomFactorY()`

### getZoomFactorY

public double getZoomFactorY()
Returns the current zoom factor in vertical direction. The value 1.0 means that the image is displayed at its original size. Anything smaller means that the image is scaled down, anything larger means that the image is scaled up. The value must not be smaller than or equal to 0.0.

Returns:
  zoom factor in vertical direction
See Also:
  - `getZoomFactorX()`

### getZoomToFit

public boolean getZoomToFit()
Returns if image display is currently set to "zoom to fit" Zoom to fit means that the image is always zoomed to fit exactly into the window.

### hasImage

public boolean hasImage()
Returns if this state encapsulates an image object.

### installProgressListeners

public void installProgressListeners(Operation op)
Adds all ProgressListener objects from the internal list of listeners to the argument operation.

### isMaximumZoom

public boolean isMaximumZoom()
Returns if the image is displayed at maximum zoom level.

### isMinimumZoom

public boolean isMinimumZoom()
Returns if the image is displayed at minimum zoom level.

### isZoomOriginalSize

public boolean isZoomOriginalSize()
Returns if the current zoom level is set to original size (each image pixel is displayed as one pixel).

### redo

public void redo()
Perform a redo operation, restore the state before the last undo operation. Before that is done, save the current state for an undo.

### resetZoomFactors

public void resetZoomFactors()

### setCurrentDirectory

public void setCurrentDirectory(String newCurrentDirectory)
Sets a new current directory.

Parameters:
  `newCurrentDirectory` - the directory to be used as current directory from now on

### setFileName

public void setFileName(String newFileName)
Sets a new file name. This is used mostly after a new image was loaded from a file or if the current image is closed (then a null value would be given to this method).

Parameters:
  `newFileName` - new name of the current file

### setImage

public void setImage(PixelImage image, boolean newModifiedState)
Sets image and modified state to argument values.

Parameters:
  `image` - new current image
  `newModifiedState` - new state of modified flag

### setStartupImageName

public void setStartupImageName(String name)

### setInterpolation

public void setInterpolation(int newInterpolation)
Sets a new interpolation type to be used for display.

Parameters:
  `newInterpolation` - an int for the interpolation type, must be one of the INTERPOLATION_xyz constants

### setLocale

public void setLocale(Locale newLocale)
Defines a new Locale to be used.

Parameters:
  `newLocale` - Locale object used from now on
See Also:
  - `setStrings(java.lang.String)`

### setStrings

public void setStrings(String iso639Code)
Set new Strings resource.

Parameters:
  `iso639Code` - language of the new Strings resource

### setZoomFactors

public void setZoomFactors(double zoomX, double zoomY)
Sets the zoom factors to the argument values.

### undo

public void undo()
Perform an undo step - the previous state will be set, the current state will be saved for a redo operation

See Also:
  - `redo()`

### zoomIn

public void zoomIn()
Increase the zoom level by one.

See Also:
  - `zoomOut()`
  - `zoomSetOriginalSize()`

### zoomOut

public void zoomOut()
Decrease the zoom level by one.

See Also:
  - `zoomIn()`
  - `zoomSetOriginalSize()`

### zoomSetOriginalSize

public void zoomSetOriginalSize()
Set the zoom level to 100 percent (1:1). Each image pixel will be displayed as one pixel

See Also:
  - `zoomIn()`
  - `zoomOut()`