public final class ListComponent<T>
extends java.lang.Object
The ComboBoxes are used to select a product and the associated Spinner is used to set the number associated with the selected Product.
The addButton is used to add an item in the ListComponent (i.e it add a new ComboBox and Spinner). The clearAllButton clear the ListComponent (i.e it deletes all the comboBoxes and spinners).
It has also two optional settings : - A button to check the nutritional values the products - A button to check the availability of products in the shops
Modifier and Type | Field and Description |
---|---|
private javafx.scene.control.Button |
addButton |
private static double |
AMOUNT_TO_STEP_BY_IN_SPINNER |
private AvailabilityChecker |
availabilityChecker |
private static int |
BIG_BUTTON_HEIGHT |
private static int |
BIG_BUTTON_WIDTH |
private javafx.scene.layout.HBox |
buttonsContainer |
private boolean |
canCheckProductAvailability |
private boolean |
canShowNutritionalValues |
private javafx.scene.control.Button |
clearButton |
private java.util.List<org.controlsfx.control.PrefixSelectionComboBox<Product>> |
comboBoxes |
private ProductDoublePairConverter<T> |
converter |
private javafx.scene.layout.VBox |
globalContainer |
private boolean |
hasBeenModified |
private javafx.scene.layout.VBox |
listContainer |
private static int |
LITTLE_BUTTON_HEIGHT |
private static int |
LITTLE_BUTTON_WIDTH |
private static double |
MAX_SPINNER_VALUE |
private static double |
MIN_SPINNER_VALUE |
private javafx.scene.control.Button |
nutritionalListButton |
private NutritionalValuesController |
nutritionalValuesController |
private javafx.collections.ObservableList<Product> |
obsAllProductList |
private java.util.List<javafx.scene.control.Spinner<java.lang.Double>> |
spinners |
Constructor and Description |
---|
ListComponent(javafx.scene.layout.VBox globalContainer,
java.util.List<Product> allProductsList,
java.util.List<T> itemList,
ProductDoublePairConverter<T> converter,
boolean canCheckProductAvailability,
AvailabilityChecker availabilityChecker,
boolean canShowNutritionalValues,
NutritionalValuesController nutritionalValuesController)
Constructs a ListComponent in a Container (VBox) and initializes it
|
ListComponent(javafx.scene.layout.VBox globalContainer,
java.util.List<Product> allProductsList,
java.util.List<T> itemList,
ProductDoublePairConverter<T> converter,
NutritionalValuesController nutritionalValuesController) |
ListComponent(javafx.scene.layout.VBox globalContainer,
java.util.List<Product> productList,
ProductDoublePairConverter<T> converter) |
Modifier and Type | Method and Description |
---|---|
private void |
addAvailabilityButton(javafx.scene.layout.HBox hBox,
org.controlsfx.control.PrefixSelectionComboBox<Product> productComboBox,
javafx.scene.control.Spinner<java.lang.Double> spinner)
Adds the availability Button in the HBox representing an item of the list.
|
private void |
addDeleteListItemButton(javafx.scene.layout.HBox listItem,
org.controlsfx.control.PrefixSelectionComboBox<Product> productComboBox,
javafx.scene.control.Spinner<java.lang.Double> spinner)
Adds The Delete Button in a List Item
|
void |
addNewProduct(Product newProduct)
Adds a new product in all the comboBoxes
|
private void |
addNutritionalButton(javafx.scene.layout.HBox listItem,
org.controlsfx.control.PrefixSelectionComboBox<Product> productComboBox,
javafx.scene.control.Spinner<java.lang.Double> spinner)
Creates and adds a button to get the nutritional value of a certain product.
|
private org.controlsfx.control.PrefixSelectionComboBox<Product> |
addProductComboBox(javafx.scene.layout.HBox listItem,
Product product)
Adds the ComboBox used to select a product in a List Item
|
private javafx.scene.control.Spinner<java.lang.Double> |
addSpinner(javafx.scene.layout.HBox listItem,
double number)
Adds the Spinner used to select the number associated with a product in a List Item
|
private javafx.scene.layout.HBox |
createListItem(javafx.util.Pair<Product,java.lang.Double> productWithDouble)
Creates a list Item on the base of a Pair (Product, Double).
|
java.util.List<T> |
getItemList()
Returns a list of Object (of type T), there is one object in the list of each item in the component
|
double |
getNumberAtPosition(int position)
Returns only the number of the item at a given position in the list component
|
private java.util.List<javafx.util.Pair<Product,java.lang.Double>> |
getProductDoublePairs()
Gets a list of (poduct, double) pairs, there is an item in the list for each element of the component
|
boolean |
hasBeenModified() |
private void |
initializeContainers(javafx.scene.layout.VBox globalContainer)
Creates a listContainer and a buttonContainer inside the globalContainer
|
private void |
maximizeAddButton()
Maximize the size of the addButton.
|
private void |
onAddItem(javafx.event.ActionEvent event)
Event Listener on the addItemButton.onAction
|
private void |
onClearAll(javafx.event.ActionEvent event)
Event Listener on clearButton.onAction
|
private void |
removeClearButton()
Removes the clearButton from the ListComponent
|
private void |
removeNutritionalListButton()
Removes the nutritional value button
(Used when the a product is removed from the list)
|
void |
removeProduct(Product product)
Taking a product as parameter, this function removes the product from the list component
|
void |
setHasBeenModified(boolean hasBeenModified) |
void |
setNumberAtPosition(int position,
double newNumber)
Sets the number of a spinner at the a given position
|
private void |
setUpAddItemButton()
Creates and sets up the addButton.
|
private void |
setUpButtons()
Sets up the Add new Item and Clear all buttons.
|
private void |
setUpClearAllButton()
Creates and sets up the clearAllButton.
|
private void |
setUpNutritionalListButton()
Creates and sets up the button used to get the total nutritional value the list.
|
void |
updateAmount(double multiplier)
Multiplies all the quantities by multiplier.
|
private static final int BIG_BUTTON_WIDTH
private static final int BIG_BUTTON_HEIGHT
private static final int LITTLE_BUTTON_WIDTH
private static final int LITTLE_BUTTON_HEIGHT
private static final double MAX_SPINNER_VALUE
private static final double MIN_SPINNER_VALUE
private static final double AMOUNT_TO_STEP_BY_IN_SPINNER
private final ProductDoublePairConverter<T> converter
private final NutritionalValuesController nutritionalValuesController
private final boolean canShowNutritionalValues
private javafx.scene.control.Button addButton
private javafx.scene.control.Button clearButton
private javafx.scene.layout.VBox globalContainer
private javafx.scene.layout.VBox listContainer
private javafx.scene.layout.HBox buttonsContainer
private java.util.List<org.controlsfx.control.PrefixSelectionComboBox<Product>> comboBoxes
private javafx.scene.control.Button nutritionalListButton
private java.util.List<javafx.scene.control.Spinner<java.lang.Double>> spinners
private AvailabilityChecker availabilityChecker
private boolean hasBeenModified
private javafx.collections.ObservableList<Product> obsAllProductList
private boolean canCheckProductAvailability
public ListComponent(javafx.scene.layout.VBox globalContainer, java.util.List<Product> allProductsList, java.util.List<T> itemList, ProductDoublePairConverter<T> converter, NutritionalValuesController nutritionalValuesController)
public ListComponent(javafx.scene.layout.VBox globalContainer, java.util.List<Product> allProductsList, java.util.List<T> itemList, ProductDoublePairConverter<T> converter, boolean canCheckProductAvailability, AvailabilityChecker availabilityChecker, boolean canShowNutritionalValues, NutritionalValuesController nutritionalValuesController)
globalContainer
- The Container in which the listContainer will be set.allProductsList
- All the product that will be selectable in the ComboBoxes.itemList
- The items with which the list must be initializedpublic ListComponent(javafx.scene.layout.VBox globalContainer, java.util.List<Product> productList, ProductDoublePairConverter<T> converter)
public boolean hasBeenModified()
public void setHasBeenModified(boolean hasBeenModified)
private void initializeContainers(javafx.scene.layout.VBox globalContainer)
globalContainer
- the container containing the list and button Containers.private void setUpButtons()
private void setUpAddItemButton()
private void setUpClearAllButton()
private void setUpNutritionalListButton()
private void onAddItem(javafx.event.ActionEvent event)
event
- private void maximizeAddButton()
private javafx.scene.layout.HBox createListItem(javafx.util.Pair<Product,java.lang.Double> productWithDouble)
productWithDouble
- The number we have to put in the Spinnerprivate void addDeleteListItemButton(javafx.scene.layout.HBox listItem, org.controlsfx.control.PrefixSelectionComboBox<Product> productComboBox, javafx.scene.control.Spinner<java.lang.Double> spinner)
listItem
- The listItem it has to removeproductComboBox
- The ComboBox of the list item it has to removespinner
- The Spinner of the list item it has to removeprivate javafx.scene.control.Spinner<java.lang.Double> addSpinner(javafx.scene.layout.HBox listItem, double number)
listItem
- The listItem that contains itnumber
- The initial value of the spinnerprivate org.controlsfx.control.PrefixSelectionComboBox<Product> addProductComboBox(javafx.scene.layout.HBox listItem, Product product)
listItem
- listItem that contains the ComboBoxproduct
- The initial selection of the ComboBoxprivate void addAvailabilityButton(javafx.scene.layout.HBox hBox, org.controlsfx.control.PrefixSelectionComboBox<Product> productComboBox, javafx.scene.control.Spinner<java.lang.Double> spinner)
hBox
- productComboBox
- spinner
- private void addNutritionalButton(javafx.scene.layout.HBox listItem, org.controlsfx.control.PrefixSelectionComboBox<Product> productComboBox, javafx.scene.control.Spinner<java.lang.Double> spinner)
listItem
- Where the button is going to be added.productComboBox
- In order to get the Item we want the information of (Event)spinner
- In order to get the quantity of the product we want (Event)private void onClearAll(javafx.event.ActionEvent event)
event
- private void removeNutritionalListButton()
private void removeClearButton()
public void addNewProduct(Product newProduct)
newProduct
- public double getNumberAtPosition(int position)
position
- The position at which we want to get the numberpublic void setNumberAtPosition(int position, double newNumber)
position
- The position of the spinner we want to changenewNumber
- The new value we want to give to itpublic void removeProduct(Product product)
product
- public java.util.List<T> getItemList()
public void updateAmount(double multiplier)
multiplier
- private java.util.List<javafx.util.Pair<Product,java.lang.Double>> getProductDoublePairs()