Class CropDialog

All Implemented Interfaces:
ActionListener, KeyListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible

public class CropDialog extends Dialog implements ActionListener, KeyListener
A dialog to enter the parameters for an image crop operation.
Author:
Marco Schmidt
See Also:
  • Field Details

    • ok

      private Button ok
    • cancel

      private Button cancel
    • x1

      private TextField x1
    • y1

      private TextField y1
    • x2

      private TextField x2
    • y2

      private TextField y2
    • width

      private int width
    • height

      private int height
    • newWidth

      private Label newWidth
    • newHeight

      private Label newHeight
    • pressedOk

      private boolean pressedOk
  • Constructor Details

    • CropDialog

      public CropDialog(Frame owner, Strings strings, int width, int height)
      Parameters:
      owner - the Frame this dialog will belong to
      strings - Strings resource to be used for text messages
      width - width of the original image, before cropping; this is used to determine the valid values for left and right column, from 0 to width - 1
      height - height of the original image, before cropping; this is used to determine the valid values for top and bottom row, from 0 to height - 1
  • Method Details

    • actionPerformed

      public void actionPerformed(ActionEvent e)
      Hides (closes) this dialog if the OK button was source of the action event (e.g. if the button was pressed).
      Specified by:
      actionPerformed in interface ActionListener
    • getHeight

      public int getHeight()
      Overrides:
      getHeight in class Component
    • getValue

      private int getValue(TextComponent textField)
      Attempts to convert the content of the argument text component to an int; if successful, returns that int, otherwise -1 is returned.
      Parameters:
      textField - the text component that is supposed to hold an int value
      Returns:
      int representation of the text component's data
    • getWidth

      public int getWidth()
      Returns the width of the to-be-cropped image as given by the current values in the text fields for left column and right column. Computes the width from those values and returns it or returns -1 if the data in the text fields is not valid for some reason.
      Overrides:
      getWidth in class Component
      Returns:
      width of cropped image or -1 if information is invalid
    • getX1

      public int getX1()
    • getX2

      public int getX2()
    • getY1

      public int getY1()
    • getY2

      public int getY2()
    • hasPressedOk

      public boolean hasPressedOk()
    • updateLabels

      private void updateLabels()
      Computes width and height of new image and updates the corresponding labels. The labels will either display width and height or a single dash if the data in the text fields is invalid.
    • keyPressed

      public void keyPressed(KeyEvent e)
      Specified by:
      keyPressed in interface KeyListener
    • keyReleased

      public void keyReleased(KeyEvent e)
      Specified by:
      keyReleased in interface KeyListener
    • keyTyped

      public void keyTyped(KeyEvent e)
      Specified by:
      keyTyped in interface KeyListener