Class ImageGrid

All Implemented Interfaces:
PreferencesSettable, ImageObserver, MenuContainer, Serializable, Accessible

public class ImageGrid extends JPanel implements PreferencesSettable
An ImageGrid allows the selection of a 2-D 'matrix' of ReadableImages and contains the mechanism for adding images to the matrix, removing images from the matrix, etc.
See Also:
  • Constructor Details

    • ImageGrid

      public ImageGrid(MessageShower parent, Preferences prefs)
      Creates a new ImageGrid, that is contained within a parent MessageShower, and with initially one image in the set of images, and a minimum of one image in the set. However, if the ImageGrid setup is specified in the user preferences, this will be used to set the grid layout.
      Parameters:
      parent - the parent MessageShower that contains this ImageGrid. If parent is non-null, it will have its cursor set appropriately when the ImageGrid is busy.
      prefs - if non-null, the user preferences from which the layout of the ImageGrid will be set.
    • ImageGrid

      public ImageGrid(MessageShower parent, Preferences prefs, int initialNCols, int minNCols, int maxNCols, int defaultNCols, int initialNRows, int minNRows, int maxNRows, int defaultNRows, boolean rowsSelectable, boolean columnsSelectable) throws IllegalArgumentException
      Creates a new ImageGrid, that is contained within a parent JFrame, and with minimum number and initial number of images in the set given by the argument.
      Parameters:
      parent - the parent MessageShower that contains this ImageGrid. If parent is non-null, it will have its cursor set appropriately when the ImageGrid is busy.
      prefs - the user Preferences from which the initial number of rows and columns of the ImageGrid will be set.
      initialNCols - the initial number of columns of images.
      minNCols - the minimum number of columns of images.
      maxNCols - the maximum number of columns of images.
      defaultNCols - the default number of columns that will be set by the setDefaults() method.
      initialNRows - the initial number of rows of images.
      minNRows - the minimum number of rows of images.
      maxNRows - the maximum number of rows of images.
      defaultNRows - the default number of rows that will be set by the setDefaults() method.
      rowsSelectable - whether rows can be selected using JRadioButtons.
      columnsSelectable - whether columns can be selected using JCheckBoxes.
      Throws:
      IllegalArgumentException - if the default number of rows or columns is outside the man/max range specified.
  • Method Details

    • getNRows

      public int getNRows()
      Returns the number of rows in the ImageGrid.
      Returns:
      the number of rows in the ImageGrid.
    • getNCols

      public int getNCols()
      Returns the number of columns in the ImageGrid.
      Returns:
      the number of columns in the ImageGrid.
    • setColumnLabel

      public void setColumnLabel(String label)
      Sets the column label to "Number of labels".
      Parameters:
      label - the label for a column.
    • setRowLabel

      public void setRowLabel(String label)
      Sets the row label to "Number of labels".
      Parameters:
      label - the label for a row.
    • setRowLabel

      public void setRowLabel(String label, int row)
      Sets the row label to "Number of labels".
      Parameters:
      label - the label for a row.
      row - the row number.
    • setRowSelectionLabel

      public void setRowSelectionLabel(String label)
      Sets the labels for the JRadioButtons that are used to select the grid row.
      Parameters:
      label - the label to display.
    • setColumnSelectionLabel

      public void setColumnSelectionLabel(String label)
      Sets the labels for the JCheckBoxes that are used to select the grid columns.
      Parameters:
      label - the label to display.
    • setRowSelectionToolTipText

      public void setRowSelectionToolTipText(String toolTipText)
      Sets the tool tip text for the JRadioButtons that are used to select the grid row.
      Parameters:
      toolTipText - the tool top to display; if the toolTipText is null, the tool tip is turned off for these components.
    • setColumnSelectionToolTipText

      public void setColumnSelectionToolTipText(String toolTipText)
      Sets the tool tip text for the JCheckBoxes that are used to select the grid columns.
      Parameters:
      toolTipText - the tool top to display; if the toolTipText is null, the tool tip is turned off for these components.
    • setNCols

      public void setNCols(int nCols)
      Sets the number of columns in the ImageGrid.
      Parameters:
      nCols - the new number of columns in the ImageGrid,
    • setNRows

      public void setNRows(int nRows)
      Sets the number of rows in the ImageGrid.
      Parameters:
      nRows - the new number of rows in the ImageGrid,
    • addCol

      public void addCol()
      Adds another column of images.
    • removeCol

      public void removeCol()
      Removes the last column of images.
    • addRow

      public void addRow()
      Adds another row of images.
    • removeRow

      public void removeRow()
      Removes the last row of images.
    • getSelectedRow

      public Integer getSelectedRow()
      Returns the index of the grid row that has been selected by the user. The user may be able to make a selection using the JRadioButton at the end of the row.
      Returns:
      the index of the grid row that has been selected by the user. Returns null if the row is not selectable, or if the user has not made a selection.
    • getSelectedColumns

      public List<Integer> getSelectedColumns()
      Returns the indices of the grid columns that have been selected by the user. The user may be able to make selections using the JCheckBoxes underneath the columns.
      Returns:
      the indices of the grid columns that have been selected by the user. Returns null if the columns are not selectable, or if the user has not made a selection.
    • setMaximumColumnsSelectable

      public void setMaximumColumnsSelectable(int max)
      Set the maximum number of columns that is simultaneously selectable by the user.
      Parameters:
      max - the maximum number of columns that is simultaneously selectable by the user.
    • selectColumn

      public void selectColumn(int col)
      Select a grid column.
      Parameters:
      col - the column to select.
      Throws:
      IndexOutOfBoundsException - if the column number is negative, or if this ImageGrid does not have enough columns to select the specified column.
    • addNColumnsChangeActionListener

      public void addNColumnsChangeActionListener(ActionListener l)
      Add an ActionListener that is to be notified when the number of columns in the ImageGrid changes.
      Parameters:
      l - the ActionListener to be added to the list of ActionListeners to be notified.
    • removeNColumnsChangeActionListener

      public void removeNColumnsChangeActionListener(ActionListener l)
      Remove an ActionListener to be notified when the number of columns in the ImageGrid changes.
      Parameters:
      l - the ActionListener to be removed from the list of ActionListeners to be notified.
    • addNRowsChangeActionListener

      public void addNRowsChangeActionListener(ActionListener l)
      Add an ActionListener that is to be notified when the number of rows in the ImageGrid changes.
      Parameters:
      l - the ActionListener to be added to the list of ActionListeners to be notified.
    • removeNRowsChangeActionListener

      public void removeNRowsChangeActionListener(ActionListener l)
      Remove an ActionListener to be notified when the number of rows in the ImageGrid changes.
      Parameters:
      l - the ActionListener to be removed from the list of ActionListeners to be notified.
    • getReadableImage

      public ReadableImage getReadableImage(int col, int row) throws IndexOutOfBoundsException, UnsetImageException, InvalidImageException
      Returns the ReadableImage for the InputImageSelectionPanel at particular location in the ImageGrid.
      Parameters:
      col - the column number (indexed from zero).
      row - the row number (indexed from zero).
      Returns:
      the com.xinapse.image.ReadableImage at the given position.
      Throws:
      IndexOutOfBoundsException - if the row or column number are outside the bounds of the ImageGrid.
      UnsetImageException - if no image has been set in the panel at the given position.
      InvalidImageException - if the image set at the given position does not yield a valid image.
    • clearAllImages

      public void clearAllImages()
      Clear all images from this ImageGrid. All file fields are set to the current working directory.
    • setDefaults

      public void setDefaults()
      Description copied from interface: PreferencesSettable
      Set the default values.
      Specified by:
      setDefaults in interface PreferencesSettable
    • savePreferences

      public void savePreferences(Preferences prefs)
      Description copied from interface: PreferencesSettable
      Save the current settings to the user Preferences at the given node name.
      Specified by:
      savePreferences in interface PreferencesSettable
      Parameters:
      prefs - the Preferences to which the current settings will be saved.
    • showError

      public void showError(String message)
      Description copied from interface: PreferencesSettable
      Show an error message (in case the current settings are invalid).
      Specified by:
      showError in interface PreferencesSettable
      Parameters:
      message - the message to show.
    • getWorkingDirectory

      public File getWorkingDirectory()
      Returns the "current working directory" for this ImageGrid. When the user chooses a new image to set in the panel, the ImageFileChooser used to select the image starts with the directory set to the current working directory. When the user, using the ImageFileChooser, moves to a different directory, the current working directory is set to the new directory.
      Returns:
      the current working directory for this ImageGrid.
    • setImageFilterClass

      public void setImageFilterClass(Class<? extends ReadableImage> c)
      Sets the class of image that will be filtered when the user first chooses a new image to set in the panel. The ImageFileChooser used to select the image starts with the correct image filter set.
      Parameters:
      c - the class of a valid image type to filter, e.g. com.xinapse.multisliceimage.UNC.UNCImage.
    • getImageFilterClass

      public Class<? extends ReadableImage> getImageFilterClass()
      Returns the class of image that will be filtered when the user first chooses a new image to set in the panel. The ImageFileChooser used to select the image starts with the correct image filter set.
      Returns:
      the class of image that will be filtered when the user first chooses a new image to set in the panel.
    • getReadableImages

      public ReadableImage[][] getReadableImages() throws UnsetImageException, InvalidImageException
      Returns a 2-D array of images that is set in the grid. The first index refers to the grid row, and the second index refers to the grid column.
      Returns:
      a 2-D array of images that is set in the grid.
      Throws:
      UnsetImageException - if any of the images in the grid has not yet been selected.
      InvalidImageException - if any of the images in the grid is not a valid ReadableImage.
    • main

      public static void main(String[] args)
      Runs the self-test on this Class.
      Parameters:
      args - ignored.