Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Mappe - programmering 2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
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
Sverre Grønhaug Halvorsen
Mappe - programmering 2
Merge requests
!39
Resolve "Improve code quality in MainPageView"
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Resolve "Improve code quality in MainPageView"
34-improve-code-quality-in-mainpageview
into
dev
Overview
0
Commits
6
Pipelines
2
Changes
8
Merged
Sverre Grønhaug Halvorsen
requested to merge
34-improve-code-quality-in-mainpageview
into
dev
1 year ago
Overview
0
Commits
6
Pipelines
2
Changes
8
Expand
Closes
#34 (closed)
0
0
Merge request reports
Compare
dev
dev (base)
and
latest version
latest version
e91ade27
6 commits,
1 year ago
8 files
+
575
−
304
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
8
Search (e.g. *.vue) (Ctrl+P)
src/main/java/edu/ntnu/idatt2003/view/components/
Styled
ComboBox.java
→
src/main/java/edu/ntnu/idatt2003/view/components/ComboBox
Factory
.java
+
66
−
0
Options
package
edu.ntnu.idatt2003.view.components
;
import
java.util.List
;
import
java.util.function.BiConsumer
;
import
javafx.event.ActionEvent
;
import
javafx.scene.control.ComboBox
;
/**
@@ -8,7 +10,14 @@ import javafx.scene.control.ComboBox;
* The combo box has a style class "combo-box" and the values are set to the specified values.
* Goal: Create a styled combo box with a specified prompt text, width, height and values.
*/
public
class
StyledComboBox
<
T
>
extends
ComboBox
<
T
>
{
public
class
ComboBoxFactory
{
/**
* Private constructor to prevent instantiation.
*/
private
ComboBoxFactory
()
{
}
/**
* Creates a styled combo box with a specified prompt text, width, height and values.
* The combo box has a style class "combo-box" and the values are set to the specified values.
@@ -18,13 +27,40 @@ public class StyledComboBox<T> extends ComboBox<T> {
* @param height The preferred height of the combo box.
* @param values The values to set in the combo box.
*/
public
StyledComboBox
(
String
promptText
,
int
width
,
int
height
,
List
<
T
>
values
)
{
super
();
this
.
setPromptText
(
promptText
);
this
.
setPrefSize
(
width
,
height
);
this
.
getStyleClass
().
add
(
"combo-box"
);
public
static
<
T
>
ComboBox
<
T
>
createComboBox
(
String
promptText
,
int
width
,
int
height
,
List
<
T
>
values
,
BiConsumer
<
ComboBox
<
T
>,
ActionEvent
>
eventHandler
)
{
return
createComboBoxWithStyle
(
promptText
,
width
,
height
,
values
,
eventHandler
);
}
public
static
<
T
>
ComboBox
<
T
>
createComboBox
(
String
promptText
,
int
width
,
int
height
,
List
<
T
>
values
,
BiConsumer
<
ComboBox
<
T
>,
ActionEvent
>
eventHandler
,
T
defaultValue
)
{
ComboBox
<
T
>
comboBox
=
createComboBoxWithStyle
(
promptText
,
width
,
height
,
values
,
eventHandler
);
comboBox
.
setValue
(
defaultValue
);
return
comboBox
;
}
/**
* Creates a styled combo box with a specified prompt text, width, height, values and events
* to be used in other methods in class.
*
* @param promptText The text to display in the combo box when it is empty.
* @param width The preferred width of the combo box.
* @param height The preferred height of the combo box.
* @param values The values to set in the combo box.
* @param eventHandler The event handler to set on the combo box.
* @return The styled combo box.
*/
private
static
<
T
>
ComboBox
<
T
>
createComboBoxWithStyle
(
String
promptText
,
int
width
,
int
height
,
List
<
T
>
values
,
BiConsumer
<
ComboBox
<
T
>,
ActionEvent
>
eventHandler
)
{
ComboBox
<
T
>
comboBox
=
new
ComboBox
<>();
comboBox
.
setPromptText
(
promptText
);
comboBox
.
setPromptText
(
promptText
);
comboBox
.
setPrefSize
(
width
,
height
);
comboBox
.
getStyleClass
().
add
(
"combo-box"
);
comboBox
.
setOnAction
(
e
->
eventHandler
.
accept
(
comboBox
,
e
));
if
(
values
!=
null
)
{
this
.
getItems
().
addAll
(
values
);
comboBox
.
getItems
().
addAll
(
values
);
}
return
comboBox
;
}
}
Loading