Skip to content

Commit 393471e

Browse files
committed
Wrote class and method documentation for javadoc, though incomplete and subject to change and edits
1 parent 1dcc14c commit 393471e

8 files changed

Lines changed: 402 additions & 52 deletions

File tree

src/main/java/sealey/javafxinventorysystem/AddPart.java

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@
2222
import java.util.Objects;
2323
import java.util.ResourceBundle;
2424

25+
/*
26+
* @author Max Sealey
27+
*
28+
* The AddPart controller controls the components for the AddPart scene, and displays radio buttons to indicate whether the created item is In-House or Outsourced,
29+
* a disabled TextField containing an auto-generated unique ID #, and TextFields for the item's name, inventory amount, price, max items possible, min items possible,
30+
* and either the machine ID (when In-House radio button is selected) or company name (when Outsourced radio button is selected). Below that is the save button and the
31+
* cancel button, both of which navigate back to the MainWindow, though only the save button adds the entered data into the table (upon input validation).
32+
* */
33+
2534
public class AddPart implements Initializable {
2635
Stage stage;
2736
Parent scene;
@@ -64,8 +73,13 @@ public class AddPart implements Initializable {
6473
@FXML
6574
private Button saveButton;
6675

67-
// Helper Functions
68-
@FXML
76+
/*
77+
* The search() method is a helper function that returns a boolean indicating whether an integer is already being used as an ID number for an existing part.
78+
* This is only called in the generateID() method to ensure that the auto-generated ID is unique.
79+
*
80+
* @param id Integer to be checked for ID uniqueness
81+
* @return boolean True if ID belongs to existing part, False otherwise
82+
* */
6983
boolean search(int id){
7084
for(Part p : Inventory.getAllParts())
7185
{
@@ -75,6 +89,12 @@ boolean search(int id){
7589
}
7690
return false;
7791
}
92+
93+
/*
94+
* The generateID() method is a helper function that generates an ID number for created part. Always returns the next unique integer in sequential order
95+
*
96+
* @return id Integer that is either 1 (if List is empty), or the next unique integer
97+
* */
7898
int generateID() {
7999
int id = 1;
80100
for(Part a : Inventory.getAllParts()) {
@@ -87,13 +107,26 @@ int generateID() {
87107
return id;
88108
}
89109

110+
/*
111+
* The onActionCancel() event handler navigates back to the MainWindow without adding any data to Inventory When the Cancel button is clicked.
112+
*
113+
* @param event ActionEvent object for the Cancel button
114+
* @throws IOException Throws error message if there is an issue with the event
115+
* */
90116
@FXML
91117
void onActionCancel(ActionEvent event) throws IOException {
92118
stage = (Stage)((Button)event.getSource()).getScene().getWindow();
93119
scene = FXMLLoader.load(Objects.requireNonNull(getClass().getResource("MainWindow.fxml")));
94120
stage.setScene(new Scene(scene));
95121
stage.show();
96122
}
123+
124+
/*
125+
* The onActionSave() event handler checks for valid input when the Save button is clicked, and if valid, adds Part to Inventory and navigates back to the MainWindow.
126+
*
127+
* @param event ActionEvent object for the Save button
128+
* @throws IOException Throws error message if there is an issue with the event
129+
* */
97130
@FXML
98131
void onActionSave(ActionEvent event) throws IOException {
99132
int id = Integer.parseInt(partIDText.getPromptText());
@@ -120,15 +153,33 @@ void onActionSave(ActionEvent event) throws IOException {
120153
stage.show();
121154
}
122155

156+
/*
157+
* When the In-House radio button is selected, the Machine ID label is displayed.
158+
*
159+
* @param event ActionEvent object for the In-House radio button
160+
* */
123161
@FXML
124162
void onActionCompanyLabel(ActionEvent event) {
125163
machineIDLabel.setText("Company Name");
126164
}
165+
166+
/*
167+
* When the Outsourced radio button is selected, the Company Name label is displayed.
168+
*
169+
* @param event ActionEvent object for the Outsourced radio button
170+
* */
127171
@FXML
128172
public void onActionMachineLabel(ActionEvent actionEvent) {
129173
machineIDLabel.setText("Machine ID");
130174
}
131175

176+
/*
177+
* The initialize() method is called when the AddPart controller is initialized. The prompt text property of the disabled partIDText TextField
178+
* is set to an auto-generated ID number.
179+
*
180+
* @param url location used to resolve relative paths for the root object, or null
181+
* @param resourceBundle resources used to localize root object or null
182+
* */
132183
@Override
133184
public void initialize(URL url, ResourceBundle resourceBundle) {
134185
partIDText.setPromptText(String.valueOf(generateID()));
Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
11
package sealey.javafxinventorysystem;
22

33
import javafx.application.Application;
4+
import javafx.collections.FXCollections;
5+
import javafx.collections.ObservableList;
46
import javafx.fxml.FXMLLoader;
57
import javafx.scene.Scene;
68
import javafx.stage.Stage;
79
import sealey.javafxinventorysystem.models.*;
810

911
import java.io.IOException;
12+
/*
13+
* @author Max Sealey
14+
*
15+
* The Main class sets the initial scene and launches the application. The javadoc folder is located
16+
* in the top level directory of the project (JavaFX-InventorySystem/javadoc).
17+
* */
1018

1119
public class Main extends Application {
20+
21+
/*
22+
* The start() method retrieves the FXML file for the main window and sets the scene.
23+
*
24+
* @param stage Stage that will display the initial scene
25+
* @throws IOException Catches issues and displays an error message if there is a problem initializing the program
26+
* */
1227
@Override
1328
public void start(Stage stage) throws IOException {
1429
testData();
@@ -23,7 +38,6 @@ public void start(Stage stage) throws IOException {
2338
private static void testData() {
2439
OutSourced part1 = new OutSourced(1, "wheel", 34.99, 16, 5, 30);
2540
OutSourced part2 = new OutSourced(2, "brake", 29.99, 18, 10, 25);
26-
2741
InHouse part3 = new InHouse(3, "handlebars", 39.99, 5, 5, 15);
2842
InHouse part4 = new InHouse(4, "chain", 14.99, 9, 7, 20);
2943

@@ -33,17 +47,21 @@ private static void testData() {
3347

3448
part1.setCompanyName("Headgum");
3549
part2.setCompanyName("OMSB");
50+
part3.setMachineId(87);
51+
part4.setMachineId(32);
3652

37-
Inventory.addPart(part1);
38-
Inventory.addPart(part2);
39-
Inventory.addPart(part3);
40-
Inventory.addPart(part4);
53+
ObservableList<Part> parts = FXCollections.observableArrayList(part1,part2,part3,part4);
54+
Inventory.setAllParts(parts);
4155

42-
Inventory.addProduct(prod1);
43-
Inventory.addProduct(prod2);
44-
Inventory.addProduct(prod3);
56+
ObservableList<Product> products = FXCollections.observableArrayList(prod1,prod2,prod3);
57+
Inventory.setAllProducts(products);
4558
}
59+
/*
60+
* The main() method is used to run the program.
61+
*
62+
* @param args String arguments that may be passed in. Will not be utilized in this program.
63+
* */
4664
public static void main(String[] args) {
47-
launch();
65+
launch(args);
4866
}
4967
}

src/main/java/sealey/javafxinventorysystem/MainWindow.java

Lines changed: 92 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@
2424
import java.util.Objects;
2525
import java.util.ResourceBundle;
2626

27+
/*
28+
* @author Max Sealey
29+
*
30+
* The MainWindow controller controls the components of the initial scene, which acts as the "home page" for the
31+
* application. It displays the Parts and Products tables, and for each respective table buttons to switch to
32+
* Add and Modify scenes, a button to delete an item, and a search bar. It also contains a button to exit the application.
33+
* */
34+
2735
public class MainWindow implements Initializable {
2836
Stage stage;
2937
Parent scene;
@@ -69,29 +77,29 @@ public class MainWindow implements Initializable {
6977
@FXML
7078
private TextField searchProductText;
7179

80+
/*
81+
* The isInt() method checks whether a provided string can be converted to an integer and returns a boolean.
82+
*
83+
* @param str The string to be checked
84+
* @return boolean Returns true if string is also an integer, false if exception is caught
85+
*/
7286
boolean isInt(String str) {
7387
try {
7488
Integer.valueOf(str);
7589
return true;
7690
} catch (NumberFormatException e) { return false; }
7791
}
7892

79-
private Part selectPart(int id) {
80-
for(Part p : Inventory.getAllParts()){
81-
if(p.getId() == id) {
82-
return p;
83-
}
84-
}
85-
return null;
86-
}
87-
private Product selectProduct(int id){
88-
for(Product p : Inventory.getAllProducts()){
89-
if(p.getId() == id) {
90-
return p;
91-
}
92-
}
93-
return null;
94-
}
93+
/*
94+
* The partFilter() method checks a string input (the text retrieved from the searchPartText TextField)
95+
* and returns a list of Parts whose name contains the string, and/or whose ID is equal to the string.
96+
* Returns an ObservableList containing all parts if the TextField is empty. If the search term does not
97+
* find any matches, error message is displayed in dialog box.
98+
*
99+
* @param search String retrieved from searchPartText
100+
* @return ObservableList of Parts containing all parts whose name contains the search parameter
101+
* and/or whose id is equal to the search parameter, or list of all Parts.
102+
* */
95103
private ObservableList<Part> partFilter(String search){
96104

97105
ObservableList<Part> temp = FXCollections.observableArrayList();
@@ -102,6 +110,17 @@ private ObservableList<Part> partFilter(String search){
102110
}
103111
return temp;
104112
}
113+
114+
/*
115+
* The productFilter() method checks a string input (the text retrieved from the searchProductText TextField)
116+
* and returns a list of Products whose name contains the string, and/or whose ID is equal to the string.
117+
* Returns an ObservableList containing all products if the TextField is empty. If the search term does not
118+
* find any matches, error message is displayed in dialog box.
119+
*
120+
* @param search String retrieved from searchProductText
121+
* @return ObservableList of Products containing all products whose name contains the search parameter
122+
* and/or whose id is equal to the search parameter, or list of all Products.
123+
* */
105124
private ObservableList<Product> productFilter(String search){
106125

107126
ObservableList<Product> temp = FXCollections.observableArrayList();
@@ -113,6 +132,12 @@ private ObservableList<Product> productFilter(String search){
113132
return temp;
114133
}
115134

135+
/*
136+
* The onActionAddPart() event handler sets the AddPart scene when the Add Button under the parts table is clicked.
137+
*
138+
* @param event ActionEvent object for the Add button
139+
* @throws IOException Throws error message if there is an issue with the event
140+
* */
116141
@FXML
117142
void onActionAddPart(ActionEvent event) throws IOException {
118143
stage = (Stage)((Button)event.getSource()).getScene().getWindow();
@@ -122,6 +147,12 @@ void onActionAddPart(ActionEvent event) throws IOException {
122147
stage.show();
123148
}
124149

150+
/*
151+
* The onActionAddProduct() event handler sets the AddProduct scene when the Add Button under the products table is clicked.
152+
*
153+
* @param event ActionEvent object for the Add button
154+
* @throws IOException Throws error message if there is an issue with the event
155+
* */
125156
@FXML
126157
void onActionAddProduct(ActionEvent event) throws IOException {
127158
stage = (Stage)((Button)event.getSource()).getScene().getWindow();
@@ -131,21 +162,46 @@ void onActionAddProduct(ActionEvent event) throws IOException {
131162
stage.show();
132163
}
133164

165+
/*
166+
* The onActionDeletePart() event handler deletes the selected part(s) when delete button is clicked.
167+
* If an item is not selected or deleted, a dialog box displays an error message.
168+
*
169+
* @param event ActionEvent object for the Delete button
170+
* @throws IOException Throws error message if there is an issue with the event
171+
* */
134172
@FXML
135173
void onActionDeletePart(ActionEvent event) {
136174
System.out.println("Delete Part");
137175
}
138176

177+
/*
178+
* The onActionDeleteProduct() event handler deletes the selected product(s) when delete button is clicked.
179+
* If an item is not selected or deleted, a dialog box displays an error message.
180+
*
181+
* @param event ActionEvent object for the Delete button
182+
* @throws IOException Throws error message if there is an issue with the event
183+
* */
139184
@FXML
140185
void onActionDeleteProduct(ActionEvent event) {
141186
System.out.println("Delete Product");
142187
}
143188

189+
/*
190+
* The onActionExit() event handler closes the application when exit button is clicked.
191+
*
192+
* @param event ActionEvent object for the Exit button
193+
* */
144194
@FXML
145195
void onActionExit(ActionEvent event) {
146196
System.exit(0);
147197
}
148198

199+
/*
200+
* The onActionModifyPart() event handler sets the ModifyPart scene when the Modify Button under the parts table is clicked.
201+
*
202+
* @param event ActionEvent object for the Modify button
203+
* @throws IOException Throws error message if there is an issue with the event
204+
* */
149205
@FXML
150206
void onActionModifyPart(ActionEvent event) throws IOException {
151207
stage = (Stage)((Button)event.getSource()).getScene().getWindow();
@@ -155,6 +211,12 @@ void onActionModifyPart(ActionEvent event) throws IOException {
155211
stage.show();
156212
}
157213

214+
/*
215+
* The onActionModifyProduct() event handler sets the ModifyProduct scene when the Modify Button under the products table is clicked.
216+
*
217+
* @param event ActionEvent object for the Modify button
218+
* @throws IOException Throws error message if there is an issue with the event
219+
* */
158220
@FXML
159221
void onActionModifyProduct(ActionEvent event) throws IOException {
160222
stage = (Stage)((Button)event.getSource()).getScene().getWindow();
@@ -164,6 +226,12 @@ void onActionModifyProduct(ActionEvent event) throws IOException {
164226
stage.show();
165227
}
166228

229+
/*
230+
* The displayData() method sets the values to be displayed in both tables.
231+
*
232+
* @param parts ObservableList of parts to be displayed in Parts table
233+
* @param products ObservableList of products to be displayed in Products table
234+
* */
167235
void displayData(ObservableList<Part> parts, ObservableList<Product> products) {
168236
partTable.setItems(parts);
169237
productTable.setItems(products);
@@ -179,6 +247,14 @@ void displayData(ObservableList<Part> parts, ObservableList<Product> products) {
179247
productPriceCol.setCellValueFactory(new PropertyValueFactory<>("price"));
180248
}
181249

250+
/*
251+
* The initialize() method is called when MainWindow controller is initialized. It displays all products currently in the inventory,
252+
* and then sets event listeners on the search bar TextFields. When the search field is selected and the 'enter' button is clicked,
253+
* the event handler is fired and the table is updated.
254+
*
255+
* @param url location used to resolve relative paths for the root object, or null
256+
* @param resourceBundle resources used to localize root object or null
257+
* */
182258
@Override
183259
public void initialize(URL url, ResourceBundle resourceBundle) {
184260
displayData(Inventory.getAllParts(),Inventory.getAllProducts());

src/main/java/sealey/javafxinventorysystem/models/InHouse.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
11
package sealey.javafxinventorysystem.models;
22

3+
/*
4+
* @author Max Sealey
5+
*
6+
* The InHouse class inherits attributes from abstract class Part, and adds Machine ID number.
7+
* */
38
public class InHouse extends Part {
49
private int machineId;
10+
11+
/*
12+
* InHouse class constructor, called when an InHouse object is created. Assigns initial values.
13+
*/
514
public InHouse(int id, String name, double price, int stock, int min, int max) {
615
super(id, name, price, stock, min, max);
716
this.machineId = getMachineId();
817
}
918

10-
// Getters and Setters
19+
/*
20+
* @return machineId machine id number to get (integer)
21+
* */
1122
public int getMachineId() {
1223
return machineId;
1324
}
25+
26+
/*
27+
* @param machineId ID number to assign
28+
* */
1429
public void setMachineId(int machineId) {
1530
this.machineId = machineId;
1631
}

0 commit comments

Comments
 (0)