Class GuiButtonController
java.lang.Object
edu.ntnu.stud.chaosgame.controller.game.GuiButtonController
Controller class for handling GUI button actions.
It notifies registered observers when a button is pressed.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ChaosCanvas
The canvas for the chaos game.private final String
The current image path.private ChaosGameDescriptionFactory
The factory for the chaos game descriptions.private final ChaosGameFileHandler
The file handler for the chaos game.private ChaosGame
The chaos game.private final ChaosGameGui
The GUI this controller is associated with.private final List
<GuiButtonObserver> The list of observers.private final PopupButtonController
The controller for the popup buttons.private final javafx.scene.image.WritableImage
The reusable image for the canvas.private int
The step counter for the game.private final javafx.animation.Timeline
The timeline for the game. -
Constructor Summary
ConstructorsConstructorDescriptionGuiButtonController
(ChaosGame game, ChaosGameGui gui) Constructs a GuiButtonController with the given game and GUI. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addObserver
(GuiButtonObserver observer) Adds an observer to the list of observers.void
Clears the canvas.void
Draws the chaos game on the canvas.private void
Initializes the description combo box.void
Loads a fractal from a file.void
Modifies the game based on the selected transformation.private void
Notifies all observers that the clear button has been pressed.private void
Notifies all observers that the load fractal from file button has been pressed.private void
Notifies all observers that the modify game button has been pressed.private void
Notifies all observers that the quit button has been pressed.private void
Notifies all observers that the save image button has been pressed.private void
Notifies all observers that the start button has been pressed.private void
Notifies all observers that the stop button has been pressed.private void
Notifies all observers that the write to file button has been pressed.void
quitGame()
Quits the game.void
Saves the image.void
Starts the game.void
stopGame()
Stops the game.private BufferedImage
toBufferedImage
(javafx.scene.image.WritableImage image) Converts a WritableImage to a BufferedImage.void
updateDescription
(int index) Updates the description of the chaos game.void
Update the description of the chaos game..void
Writes the fractal to a file.
-
Field Details
-
gui
The GUI this controller is associated with. -
timeline
private final javafx.animation.Timeline timelineThe timeline for the game. -
popupButtonController
The controller for the popup buttons. -
observers
The list of observers. -
fileHandler
The file handler for the chaos game. -
game
The chaos game. -
factory
The factory for the chaos game descriptions. -
chaosCanvas
The canvas for the chaos game. -
currentImagePath
The current image path. -
stepCounter
private int stepCounterThe step counter for the game. -
reusableImage
private final javafx.scene.image.WritableImage reusableImageThe reusable image for the canvas.
-
-
Constructor Details
-
GuiButtonController
Constructs a GuiButtonController with the given game and GUI.- Parameters:
game
- the Chaos Game model.gui
- the Chaos Game GUI.
-
-
Method Details
-
addObserver
Adds an observer to the list of observers.- Parameters:
observer
- the observer to add.
-
notifyStartButtonPressed
private void notifyStartButtonPressed()Notifies all observers that the start button has been pressed. -
notifyStopButtonPressed
private void notifyStopButtonPressed()Notifies all observers that the stop button has been pressed. -
notifyClearButtonPressed
private void notifyClearButtonPressed()Notifies all observers that the clear button has been pressed. -
notifyQuitButtonPressed
private void notifyQuitButtonPressed()Notifies all observers that the quit button has been pressed. -
notifySaveImageButtonPressed
private void notifySaveImageButtonPressed()Notifies all observers that the save image button has been pressed. -
notifyLoadFractalFromFileButtonPressed
private void notifyLoadFractalFromFileButtonPressed()Notifies all observers that the load fractal from file button has been pressed. -
notifyWriteToFileButtonPressed
private void notifyWriteToFileButtonPressed()Notifies all observers that the write to file button has been pressed. -
notifyModifyGameButtonPressed
private void notifyModifyGameButtonPressed()Notifies all observers that the modify game button has been pressed. -
startGame
public void startGame()Starts the game. -
stopGame
public void stopGame()Stops the game. -
clearCanvas
public void clearCanvas()Clears the canvas. -
quitGame
public void quitGame()Quits the game. -
saveImage
public void saveImage()Saves the image. -
toBufferedImage
Converts a WritableImage to a BufferedImage.- Parameters:
image
- the WritableImage to convert.- Returns:
- the converted BufferedImage.
-
loadFractalFromFile
public void loadFractalFromFile()Loads a fractal from a file. -
writeFractalToFile
public void writeFractalToFile()Writes the fractal to a file. -
modifyGame
public void modifyGame()Modifies the game based on the selected transformation. -
initializeDescriptionComboBox
private void initializeDescriptionComboBox()Initializes the description combo box. -
updateDescriptionComboBox
public void updateDescriptionComboBox()Update the description of the chaos game.. -
drawChaosGame
public void drawChaosGame()Draws the chaos game on the canvas. -
updateDescription
public void updateDescription(int index) Updates the description of the chaos game.- Parameters:
index
- the index of the new description in the list of factory descriptions.
-