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 Details

    • DEFAULT_MAX_UNDO_IMAGES

      public static final int DEFAULT_MAX_UNDO_IMAGES
      The default number of undo steps possible.
      See Also:
    • DEFAULT_MAX_REDO_IMAGES

      public static final int DEFAULT_MAX_REDO_IMAGES
      The default number of redo steps possible.
      See Also:
    • 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:
    • INTERPOLATION_NEAREST_NEIGHBOR

      public static final int INTERPOLATION_NEAREST_NEIGHBOR
      Integer constant for nearest neighbor interpolation. A fast but ugly method.
      See Also:
    • INTERPOLATION_BILINEAR

      public static final int INTERPOLATION_BILINEAR
      Integer constant for bilinear neighbor interpolation. A slow but nice method.
      See Also:
    • 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:
    • DEFAULT_INTERPOLATION

      public static final int DEFAULT_INTERPOLATION
      The default interpolation type, one of the three INTERPOLATION_xyz constants.
      See Also:
    • 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

      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

      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

      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:
    • 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
      See Also: