cs2110.assignment3
Class ComparisonGUI

java.lang.Object
  extended by cs2110.assignment3.ComparisonGUI

public class ComparisonGUI
extends java.lang.Object

Base class for implementing the species comparison GUI.

You will subclass ComparisonGUI to make your comparison GUI.

The GUI consists of a table with a picture of each species, and two larger pictures that are intended to show the currently selected species and its closest relative, as computed by your species distance algorithm.

When the user clicks on a cell in the table, the method onSelectCell is called. Your subclass should override onSelectCell to exhibit the behavior described in the assignment.

You will refer to cells by their number, 0 through n-1, where n is the number of species given to the ComparisonGUI's constructor.

Read the documentation for each method to learn what you can do with this class.

Author:
Lonnie Princehouse

Constructor Summary
ComparisonGUI(int n)
          The constructor takes a single argument: the number of species you plan on placing in the GUI's comparison table.
 
Method Summary
 int getColumns()
          Get the number of columns in the species table
 javax.swing.JPanel getComparisonPanel()
          Optional: For extending the user interface.
 javax.swing.JFrame getFrame()
          Optional: For extending the user interface.
 javax.swing.JPanel getGridPanel()
          Optional: For extending the user interface.
 int getRows()
          Get the number of rows in the species table
 void onSelectCell(int cell)
          This method will be called when the user clicks a cell in the table.
 void run()
           
 void setCellColor(int cell, java.awt.Color color)
          Sets the background color of a cell, specified as an instance of java.awt.Color
 void setCellColor(int cell, double red, double green, double blue)
          Sets the background color of a cell.
 void setCellImage(int cell, java.lang.String filename)
          Load an image into the desired cell.
 void setClosestRelativeInfo(java.lang.String name, java.lang.String imageFile)
          Set the name and image file of the current most closely related species.
 void setSelectedInfo(java.lang.String name, java.lang.String imageFile)
          Set the name and image file of the currently selected species.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ComparisonGUI

public ComparisonGUI(int n)
The constructor takes a single argument: the number of species you plan on placing in the GUI's comparison table.

After constructing an instance of ComparisonGUI, you should call setCellImage for each cell (numbered 0 through n-1) to place images in the cells.

Parameters:
n - Number of species
Method Detail

getFrame

public javax.swing.JFrame getFrame()
Optional: For extending the user interface. Returns the top-level frame (A.K.A. top-level window). The frame's content panel (getFrame().getContentPanel()) uses a vertical BoxLayout manager. Components added will appear below the existing GUI.

Returns:
The top-level frame.

getComparisonPanel

public javax.swing.JPanel getComparisonPanel()
Optional: For extending the user interface. The comparison panel is the panel containing the larger images and text. It uses a vertical BoxLayout manager.

Returns:
The comparison panel JPanel

getGridPanel

public javax.swing.JPanel getGridPanel()
Optional: For extending the user interface. The grid panel uses a GridLayout that contains buttons for each species..

Returns:
The grid panel JPanel

getColumns

public int getColumns()
Get the number of columns in the species table

Returns:
Number of columns in the species table

getRows

public int getRows()
Get the number of rows in the species table

Returns:
Number of rows in the species table

onSelectCell

public void onSelectCell(int cell)
This method will be called when the user clicks a cell in the table. Your subclass should override this method.

Parameters:
cell -

setCellImage

public void setCellImage(int cell,
                         java.lang.String filename)
                  throws InvalidCellNumberException
Load an image into the desired cell.

Parameters:
cell - Cell number
filename - Path to the image file
Throws:
InvalidCellNumberException

setCellColor

public void setCellColor(int cell,
                         double red,
                         double green,
                         double blue)
                  throws InvalidColorException,
                         InvalidCellNumberException
Sets the background color of a cell. Colors are specified as (r,g,b) triples between zero and one.

Parameters:
cell - Cell number
red - Red component. Must be between 0 and 1.
green - Green component. Must be between 0 and 1.
blue - Blue component. Must be between 0 and 1.
Throws:
InvalidColorException
InvalidCellNumberException

setCellColor

public void setCellColor(int cell,
                         java.awt.Color color)
                  throws InvalidCellNumberException
Sets the background color of a cell, specified as an instance of java.awt.Color

Parameters:
cell - Cell number
color - Desired background color
Throws:
InvalidCellNumberException

setSelectedInfo

public void setSelectedInfo(java.lang.String name,
                            java.lang.String imageFile)
Set the name and image file of the currently selected species. These will appear under "Selected:" at the right of the window.

Parameters:
name - Species name
imageFile - Image file path

setClosestRelativeInfo

public void setClosestRelativeInfo(java.lang.String name,
                                   java.lang.String imageFile)
Set the name and image file of the current most closely related species. These will appear under "Closest relative:" at the right of the window.

Parameters:
name - Species name
imageFile - Image file path

run

public void run()