Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
IDATT2003 Mappevurdering
Manage
Activity
Members
Labels
Plan
Issues
13
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Håvard Johannes Versto Daleng
IDATT2003 Mappevurdering
Commits
3127a10d
Commit
3127a10d
authored
9 months ago
by
Håvard Daleng
Browse files
Options
Downloads
Patches
Plain Diff
Rebased
parent
b90e5086
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/edu/ntnu/stud/chaosgame/view/ChaosGameGui.java
+40
-54
40 additions, 54 deletions
src/main/java/edu/ntnu/stud/chaosgame/view/ChaosGameGui.java
with
40 additions
and
54 deletions
src/main/java/edu/ntnu/stud/chaosgame/view/ChaosGameGui.java
+
40
−
54
View file @
3127a10d
...
@@ -40,12 +40,16 @@ import java.io.IOException;
...
@@ -40,12 +40,16 @@ import java.io.IOException;
public
class
ChaosGameGui
implements
ChaosGameObserver
{
public
class
ChaosGameGui
implements
ChaosGameObserver
{
private
int
currentLine
=
0
;
private
int
currentLine
=
0
;
/**
* The primary stage for the GUI.
*/
private
Stage
primaryStage
;
private
Stage
primaryStage
;
/**
* The aspect ratio of the GUI.
*/
private
double
aspectRatio
;
private
double
aspectRatio
;
/**
/**
* The canvas for this GUI.
* The canvas for this GUI.
*/
*/
...
@@ -122,13 +126,24 @@ public class ChaosGameGui implements ChaosGameObserver {
...
@@ -122,13 +126,24 @@ public class ChaosGameGui implements ChaosGameObserver {
*/
*/
private
Button
clearButton
;
private
Button
clearButton
;
/**
* The quit button for the GUI.
*/
private
Button
quitButton
;
private
Button
quitButton
;
/**
* The side menu button for the GUI.
*/
private
Button
sideMenuButton
;
private
Button
sideMenuButton
;
/**
/**
* The load fractal from file and write fractal to file buttons for the GUI.
* The load fractal from file and write fractal to file buttons for the GUI.
*/
*/
private
Button
loadFractalFromFileButton
;
private
Button
loadFractalFromFileButton
;
/**
* The write fractal to file button for the GUI.
*/
private
Button
writeFractalToFileButton
;
private
Button
writeFractalToFileButton
;
/**
/**
...
@@ -172,23 +187,24 @@ public class ChaosGameGui implements ChaosGameObserver {
...
@@ -172,23 +187,24 @@ public class ChaosGameGui implements ChaosGameObserver {
* @param primaryStage the primary stage for the GUI.
* @param primaryStage the primary stage for the GUI.
* @throws IOException if the GUI fails to initialize.
* @throws IOException if the GUI fails to initialize.
*/
*/
public
ChaosGameGui
(
Stage
primaryStage
)
throws
IOException
{
public
ChaosGameGui
(
Stage
primaryStage
)
throws
IOException
{
this
.
primaryStage
=
primaryStage
;
this
.
primaryStage
=
primaryStage
;
this
.
initializeComponents
();
this
.
initializeComponents
();
this
.
initializeGameComponents
();
this
.
initializeGameComponents
();
this
.
controller
=
new
GuiButtonController
(
game
,
this
);
// Initialize controller here
this
.
controller
=
new
GuiButtonController
(
game
,
this
);
// Initialize controller here
primaryStage
.
setTitle
(
"Fractal Chaos Game"
);
primaryStage
.
setTitle
(
"Fractal Chaos Game"
);
primaryStage
.
setScene
(
scene
);
primaryStage
.
setScene
(
scene
);
primaryStage
.
setOnShown
(
event
->
this
.
imageView
.
requestFocus
());
primaryStage
.
setOnShown
(
event
->
this
.
imageView
.
requestFocus
());
primaryStage
.
show
();
primaryStage
.
show
();
// Initialize aspect ratio based on initial dimensions
// Initialize aspect ratio based on initial dimensions
this
.
aspectRatio
=
(
double
)
width
/
height
;
this
.
aspectRatio
=
(
double
)
width
/
height
;
// Add listeners to handle window size changes
// Add listeners to handle window size changes
scene
.
widthProperty
().
addListener
((
observable
,
oldValue
,
newValue
)
->
{
scene
.
widthProperty
().
addListener
((
observable
,
oldValue
,
newValue
)
->
{
resizeCanvas
();
resizeCanvas
();
});
});
scene
.
heightProperty
().
addListener
((
observable
,
oldValue
,
newValue
)
->
{
scene
.
heightProperty
().
addListener
((
observable
,
oldValue
,
newValue
)
->
{
resizeCanvas
();
resizeCanvas
();
...
@@ -200,6 +216,8 @@ sideMenu.prefWidthProperty().bind(scene.widthProperty().multiply(0.2)); // 20% o
...
@@ -200,6 +216,8 @@ sideMenu.prefWidthProperty().bind(scene.widthProperty().multiply(0.2)); // 20% o
// Bind the height of the sideMenu to the height of the scene
// Bind the height of the sideMenu to the height of the scene
sideMenu
.
prefHeightProperty
().
bind
(
scene
.
heightProperty
());
sideMenu
.
prefHeightProperty
().
bind
(
scene
.
heightProperty
());
}
}
/**
/**
* Initialize the components of the GUI.
* Initialize the components of the GUI.
*/
*/
...
@@ -226,35 +244,6 @@ sideMenu.prefHeightProperty().bind(scene.heightProperty());
...
@@ -226,35 +244,6 @@ sideMenu.prefHeightProperty().bind(scene.heightProperty());
return
textField
;
return
textField
;
}
}
/**
* Initialize the main buttons for the GUI.
*/
// private void initializeMainButtons() {
// this.startButton = new Button("Start");
// startButton.setOnAction(event -> controller.startGame());
// this.stopButton = new Button("Stop");
// stopButton.setOnAction(event -> controller.stopGame());
//
// this.newButton = new Button("New");
//
// newButton.setOnAction(event ->{
// this.canvas.getGraphicsContext2D().clearRect(0, 0, canvas.getWidth(), canvas.getHeight());
// chaosCanvas.clearCanvas();
// });
//
// this.clearButton = new Button("Clear");
//
// clearButton.setOnAction(event -> {
// getImageView().setImage(null);
// setCurrentLine(0);
// });
//
// // Quit button
// this.quitButton = new Button("Quit");
// quitButton.setOnAction(event -> Platform.exit());
//
// }
/**
/**
* Initialize the components related to the chaos game itself.
* Initialize the components related to the chaos game itself.
*/
*/
...
@@ -313,8 +302,6 @@ sideMenu.prefHeightProperty().bind(scene.heightProperty());
...
@@ -313,8 +302,6 @@ sideMenu.prefHeightProperty().bind(scene.heightProperty());
this
.
improvedBarnsleyButton
=
new
RadioButton
(
"Improved Barnsley"
);
this
.
improvedBarnsleyButton
=
new
RadioButton
(
"Improved Barnsley"
);
improvedBarnsleyButton
.
setToggleGroup
(
group
);
improvedBarnsleyButton
.
setToggleGroup
(
group
);
// Load fractal file button and tooltip
// Load fractal file button and tooltip
this
.
loadFractalFromFileButton
=
new
Button
(
"Load Fractal"
);
this
.
loadFractalFromFileButton
=
new
Button
(
"Load Fractal"
);
Tooltip
loadFractalFromFileButtonTooltip
=
new
Tooltip
(
"Load a text file describing a new fractal chaos game"
);
Tooltip
loadFractalFromFileButtonTooltip
=
new
Tooltip
(
"Load a text file describing a new fractal chaos game"
);
...
@@ -354,7 +341,6 @@ sideMenu.prefHeightProperty().bind(scene.heightProperty());
...
@@ -354,7 +341,6 @@ sideMenu.prefHeightProperty().bind(scene.heightProperty());
Tooltip
clearButtonTooltip
=
new
Tooltip
(
"Clear the current fracal"
);
Tooltip
clearButtonTooltip
=
new
Tooltip
(
"Clear the current fracal"
);
Tooltip
quitButtonTooltip
=
new
Tooltip
(
"Quit the application"
);
Tooltip
quitButtonTooltip
=
new
Tooltip
(
"Quit the application"
);
// Attach Tooltips to Buttons
// Attach Tooltips to Buttons
Tooltip
.
install
(
startButton
,
startButtonTooltip
);
Tooltip
.
install
(
startButton
,
startButtonTooltip
);
Tooltip
.
install
(
stopButton
,
stopButtonTooltip
);
Tooltip
.
install
(
stopButton
,
stopButtonTooltip
);
...
@@ -362,6 +348,7 @@ sideMenu.prefHeightProperty().bind(scene.heightProperty());
...
@@ -362,6 +348,7 @@ sideMenu.prefHeightProperty().bind(scene.heightProperty());
Tooltip
.
install
(
quitButton
,
quitButtonTooltip
);
Tooltip
.
install
(
quitButton
,
quitButtonTooltip
);
this
.
sideMenu
=
new
VBox
();
this
.
sideMenu
=
new
VBox
();
//this.sideMenu.setAlignment(Pos.CENTER);
// Parameters
// Parameters
VBox
parameterBox
=
new
VBox
();
VBox
parameterBox
=
new
VBox
();
VBox
controlButtonBox
=
new
VBox
();
VBox
controlButtonBox
=
new
VBox
();
...
@@ -466,9 +453,9 @@ sideMenu.prefHeightProperty().bind(scene.heightProperty());
...
@@ -466,9 +453,9 @@ sideMenu.prefHeightProperty().bind(scene.heightProperty());
parameterBox
.
setPadding
(
new
Insets
(
10
));
parameterBox
.
setPadding
(
new
Insets
(
10
));
// Add basic control buttons
// Add basic control buttons
controlButtonBox
.
getChildren
().
addAll
(
canvasLabel
,
startButton
,
stopButton
,
clearButton
);
controlButtonBox
.
setAlignment
(
Pos
.
CENTER
);
controlButtonBox
.
setAlignment
(
Pos
.
CENTER
);
controlButtonBox
.
getChildren
().
addAll
(
canvasLabel
,
startButton
,
stopButton
,
clearButton
);
controlButtonBox
.
setSpacing
(
5
);
controlButtonBox
.
setSpacing
(
5
);
sideMenu
.
getChildren
().
add
(
controlButtonBox
);
sideMenu
.
getChildren
().
add
(
controlButtonBox
);
...
@@ -580,7 +567,6 @@ sideMenu.prefHeightProperty().bind(scene.heightProperty());
...
@@ -580,7 +567,6 @@ sideMenu.prefHeightProperty().bind(scene.heightProperty());
return
this
.
chaosCanvas
;
return
this
.
chaosCanvas
;
}
}
public
int
getWidth
(){
public
int
getWidth
(){
return
this
.
width
;
return
this
.
width
;
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment