Package net.sourceforge.jiu.apps
Class EditorState
java.lang.Object
net.sourceforge.jiu.apps.EditorState
- All Implemented Interfaces:
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
FieldsModifier and TypeFieldDescriptionprivate String
private PixelImage
static final int
The default interpolation type, one of the three INTERPOLATION_xyz constants.static final int
The default number of redo steps possible.static final int
The default number of undo steps possible.private String
private int
static final int
Integer constant for bicubic interpolation.static final int
Integer constant for bilinear neighbor interpolation.static final int
Integer constant for nearest neighbor interpolation.private Locale
private int
private int
private boolean
static final int
The index into theZOOM_LEVELS
array that holds the original size zoom level (100 percent).private Vector
private Vector
private Vector
private String
private Strings
private Vector
private Vector
static final int[]
All allowed zoom levels, as percentage values in ascending order.private double
private double
private int
private boolean
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
ConstructorsConstructorDescriptionCreate new EditorState object and initialize its private fields to default values. -
Method Summary
Modifier and TypeMethodDescriptionprivate void
addImageToRedo
(PixelImage image, boolean modifiedState) private void
addImageToUndo
(PixelImage image, boolean modifiedState) void
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
void
void
Returns the current directory.Returns the name of the file from which the current image was loaded.getImage()
Returns the image object currently loaded.int
Returns the current interpolation type, one of the INTERPOLATION_xyz constants.Returns the Locale object currently used.boolean
Returns the current modified state (true if image was modified and not saved after modification, false otherwise).Returns the internal list of progress listeners.Returns the Strings object currently in use.double
Returns the current zoom factor in horizontal direction.double
Returns the current zoom factor in vertical direction.boolean
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
Adds all ProgressListener objects from the internal list of listeners to the argument operation.boolean
Returns if the image is displayed at maximum zoom level.boolean
Returns if the image is displayed at minimum zoom level.boolean
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
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
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 operationvoid
zoomIn()
Increase the zoom level by one.void
zoomOut()
Decrease the zoom level by one.void
Set the zoom level to 100 percent (1:1).
-
Field Details
-
DEFAULT_MAX_UNDO_IMAGES
public static final int DEFAULT_MAX_UNDO_IMAGESThe default number of undo steps possible.- See Also:
-
DEFAULT_MAX_REDO_IMAGES
public static final int DEFAULT_MAX_REDO_IMAGESThe default number of redo steps possible.- See Also:
-
ZOOM_LEVELS
public static final int[] ZOOM_LEVELSAll allowed zoom levels, as percentage values in ascending order. -
ORIGINAL_SIZE_ZOOM_INDEX
public static final int ORIGINAL_SIZE_ZOOM_INDEXThe index into theZOOM_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:
-
INTERPOLATION_NEAREST_NEIGHBOR
public static final int INTERPOLATION_NEAREST_NEIGHBORInteger constant for nearest neighbor interpolation. A fast but ugly method.- See Also:
-
INTERPOLATION_BILINEAR
public static final int INTERPOLATION_BILINEARInteger constant for bilinear neighbor interpolation. A slow but nice method.- See Also:
-
INTERPOLATION_BICUBIC
public static final int INTERPOLATION_BICUBICInteger constant for bicubic interpolation. A very slow method, but with the nicest output of the three supported interpolation types.- See Also:
-
DEFAULT_INTERPOLATION
public static final int DEFAULT_INTERPOLATIONThe default interpolation type, one of the three INTERPOLATION_xyz constants.- See Also:
-
currentDirectory
-
fileName
-
currentImage
-
interpolation
private int interpolation -
locale
-
maxRedoImages
private int maxRedoImages -
maxUndoImages
private int maxUndoImages -
modified
private boolean modified -
progressListeners
-
redoImages
-
redoModified
-
startupImageName
-
strings
-
undoImages
-
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
-
addImageToUndo
-
addProgressListener
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
Returns the current directory. This directory will be used when file dialogs are opened. -
getFileName
Returns the name of the file from which the current image was loaded. -
getImage
Returns the image object currently loaded. -
getInterpolation
public int getInterpolation()Returns the current interpolation type, one of the INTERPOLATION_xyz constants. -
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
Returns the internal list of progress listeners. -
getStartupImageName
-
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
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:
-
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
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
Sets a new current directory.- Parameters:
newCurrentDirectory
- the directory to be used as current directory from now on
-
setFileName
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
Sets image and modified state to argument values.- Parameters:
image
- new current imagenewModifiedState
- new state of modified flag
-
setStartupImageName
-
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
Defines a new Locale to be used.- Parameters:
newLocale
- Locale object used from now on- See Also:
-
setStrings
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:
-
zoomIn
public void zoomIn()Increase the zoom level by one.- See Also:
-
zoomOut
public void zoomOut()Decrease the zoom level by one.- See Also:
-
zoomSetOriginalSize
public void zoomSetOriginalSize()Set the zoom level to 100 percent (1:1). Each image pixel will be displayed as one pixel
-