com.eriksilkensen.sudoku
Class SudokuView

java.lang.Object
  extended by com.eriksilkensen.sudoku.SudokuView
All Implemented Interfaces:
SudokuObserver, Observer

public class SudokuView
extends java.lang.Object
implements SudokuObserver

SudokuView is the View component in the M-V-C framework and so behaves like one would expect of a View.

It creates the entire GUI, and registers itself to listen in on events happening in the Model. It uses a Control in order to communicate with the Model, and allows for the Control to modify its state with lots of set() - type methods.

Since:
1.0
Version:
04/29/07
Author:
Erik Silkensen

Constructor Summary
SudokuView(SudokuControl controller)
          The only constructor for a SudokuView.
 
Method Summary
 void createView()
          Creates the entire GUI
 void gameWon()
          Required by the SudokuObserver interface.
protected  javax.swing.JFrame getFrame()
          Returns the JFrame same-package and derived classes
 java.lang.String getHintLimit()
          Hosts in a networked game have the ability to set a limit on the number of Hints that can be used in the game.
 int getID()
          getId() prompts the user for the desired ID number of the Board they wish to play.
 void initRadioSelector()
          Initializes the radio controls by enabling them and selecting the number 1
 boolean isTimerEnabled()
          Returns whether or not the Timer is enabled
 java.lang.String requestName()
          Required by the SudokuObserver interface.
 void resetGameLabels()
          Resets the top two labels to their default settings
 void setAllEnabled(boolean enabled)
          Sets all important controls to be enabled or disabled
 void setAllNetworkEnabled(boolean enabled)
          Sets all network controls to be enabled or disabled
 void setAllNonNetworkEnabled(boolean enabled)
          Sets all controls that aren't using during a multiplayer game to be enabled or disabled
 void setBestTimesEnabled(boolean enabled)
          Sets the best time controls to be enabled or disabled
 void setButtonText(int row, int col, int playerValue)
          setButtonText() is crucial in updating the individual button cells with whatever value the user has decided to place at the specified location.
 void setChatEnabled(boolean enabled)
          Sets the network chatting control to be enabled or disabled
 void setCheckEnabled(boolean enabled)
          Sets the check controls to be enabled or disabled
 void setClearEnabled(boolean enabled)
          Sets the clear controls to be enabled or disabled
 void setConnectEnabled(boolean enabled)
          Sets the network connection control to be enabled or disabled
 void setDisconnectEnabled(boolean enabled)
          Sets the network disconnection control to be enabled or disabled
 void setGiveUpEnabled(boolean enabled)
          Sets the give up controls to be enabled or disabled
 void setHintButton(Hint hint)
          Will place the passed hint on the Board.
 void setHintsEnabled(boolean enabled)
          Sets the hint controls to be enabled or disabled
 void setNetworkConfigEnabled(boolean enabled)
          Sets the network configuration contorl to be enabled or disabled
 void setPauseEnabled(boolean enabled)
          Sets the pause controls to be enabled or disabled
 void setPrintEnabled(boolean enabled)
          Sets the printing controls to be enabled or disabled
 void setRadiosEnabled(boolean enabled)
          Sets the radio controls to be enabled or disabled
 void setSaveEnabled(boolean enabled)
          Sets the save controls to be enabled or disabled
 void setStartEnabled(boolean enabled)
          Sets the network starting control to be enabled or disabled
 void setTime(int time)
           
 void setTimerEnabled(boolean enabled)
          Sets whether or not the Timer should be used when playing games
 void setTimerLabelText(java.lang.String text)
          Sets the timer label's text
 void show()
          Simply shows the View by first centering the frame and then setting it to be visible.
 void showHomeScreen()
          Handy method for bringing the user back to the 'Home Screen' after ending a game
 void startTimer()
          Starts the Timer
 void stopTimer()
          Stops the Timer
 void update(Observable obs, java.lang.Object arg)
          update() is what gets called when an Observable wants to update its Observers.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SudokuView

public SudokuView(SudokuControl controller)

The only constructor for a SudokuView. It requires a Control immediately in order to communicate with the Model.

The constructor registers the Observer with the Observable Model (through the Control), creates the Timer, and initializes the playerValue. The Control decides when to actually create the View.

Method Detail

createView

public void createView()
Creates the entire GUI


show

public void show()
Simply shows the View by first centering the frame and then setting it to be visible.


startTimer

public void startTimer()
Starts the Timer


stopTimer

public void stopTimer()
Stops the Timer


setTimerEnabled

public void setTimerEnabled(boolean enabled)
Sets whether or not the Timer should be used when playing games


isTimerEnabled

public boolean isTimerEnabled()
Returns whether or not the Timer is enabled


showHomeScreen

public void showHomeScreen()
Handy method for bringing the user back to the 'Home Screen' after ending a game


setTimerLabelText

public void setTimerLabelText(java.lang.String text)
Sets the timer label's text


setPauseEnabled

public void setPauseEnabled(boolean enabled)
Sets the pause controls to be enabled or disabled


setClearEnabled

public void setClearEnabled(boolean enabled)
Sets the clear controls to be enabled or disabled


setRadiosEnabled

public void setRadiosEnabled(boolean enabled)
Sets the radio controls to be enabled or disabled


setBestTimesEnabled

public void setBestTimesEnabled(boolean enabled)
Sets the best time controls to be enabled or disabled


setHintsEnabled

public void setHintsEnabled(boolean enabled)
Sets the hint controls to be enabled or disabled


setCheckEnabled

public void setCheckEnabled(boolean enabled)
Sets the check controls to be enabled or disabled


setGiveUpEnabled

public void setGiveUpEnabled(boolean enabled)
Sets the give up controls to be enabled or disabled


setSaveEnabled

public void setSaveEnabled(boolean enabled)
Sets the save controls to be enabled or disabled


setPrintEnabled

public void setPrintEnabled(boolean enabled)
Sets the printing controls to be enabled or disabled


setConnectEnabled

public void setConnectEnabled(boolean enabled)
Sets the network connection control to be enabled or disabled


setDisconnectEnabled

public void setDisconnectEnabled(boolean enabled)
Sets the network disconnection control to be enabled or disabled


setStartEnabled

public void setStartEnabled(boolean enabled)
Sets the network starting control to be enabled or disabled


setChatEnabled

public void setChatEnabled(boolean enabled)
Sets the network chatting control to be enabled or disabled


setNetworkConfigEnabled

public void setNetworkConfigEnabled(boolean enabled)
Sets the network configuration contorl to be enabled or disabled


setAllNonNetworkEnabled

public void setAllNonNetworkEnabled(boolean enabled)
Sets all controls that aren't using during a multiplayer game to be enabled or disabled


setAllNetworkEnabled

public void setAllNetworkEnabled(boolean enabled)
Sets all network controls to be enabled or disabled


setAllEnabled

public void setAllEnabled(boolean enabled)
Sets all important controls to be enabled or disabled


initRadioSelector

public void initRadioSelector()
Initializes the radio controls by enabling them and selecting the number 1


update

public void update(Observable obs,
                   java.lang.Object arg)
update() is what gets called when an Observable wants to update its Observers. The way this method operates isn't entirely straightforward. But, the basic idea is that an Observable object can 'push' an optional argument to its Observers, which they can then do with whatever they please. If the arg is a Board, it can be assumed that the Model is asking for the View's complete visualization of the current 'Board' to be trashed and replaced with the new one. If, on the other hand, the arg is an int[], it can be assumed that the Model is has checked the user's Board and is returning an array containing the coordinates of every incorrectly placed Cell in the form (arg[n],arg[n+1]). Intuitive, right?

Specified by:
update in interface Observer

resetGameLabels

public void resetGameLabels()
Resets the top two labels to their default settings


setHintButton

public void setHintButton(Hint hint)
Will place the passed hint on the Board. Since a Hint encapsulates its own location along with value, everything works out easily.


gameWon

public void gameWon()
Required by the SudokuObserver interface. Called when a game is won.

Specified by:
gameWon in interface SudokuObserver

getFrame

protected javax.swing.JFrame getFrame()
Returns the JFrame same-package and derived classes


requestName

public java.lang.String requestName()
Required by the SudokuObserver interface. Gets a name from someone who has gotten a Best Time.

Specified by:
requestName in interface SudokuObserver

getID

public int getID()
getId() prompts the user for the desired ID number of the Board they wish to play. It provides for any sort of troubled input the user may throw at it, and simply loops around until the user surrenders.


setTime

public void setTime(int time)

getHintLimit

public java.lang.String getHintLimit()
Hosts in a networked game have the ability to set a limit on the number of Hints that can be used in the game. This method fetches that number from the Host.


setButtonText

public void setButtonText(int row,
                          int col,
                          int playerValue)
setButtonText() is crucial in updating the individual button cells with whatever value the user has decided to place at the specified location.