-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLandingPage.java
More file actions
108 lines (96 loc) · 4.04 KB
/
LandingPage.java
File metadata and controls
108 lines (96 loc) · 4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import javax.swing.*;
import java.awt.*;
import java.io.File;
public class LandingPage extends JFrame {
private JList<String> savedPlansList;
private DefaultListModel<String> listModel;
public LandingPage() {
//Setup GUI
setTitle("Floor Plan Manager");
setSize(600, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
JPanel buttonPanel = new JPanel();
JButton newPlanButton = new JButton("Create New Floor Plan");
JButton loadPlanButton = new JButton("Load Selected Floor Plan");
JButton deletePlanButton = new JButton("Delete Selected Floor Plan");
newPlanButton.addActionListener(e -> createNewFloorPlan());
loadPlanButton.addActionListener(e -> loadSelectedFloorPlan());
deletePlanButton.addActionListener(e -> deleteSelectedFloorPlan());
buttonPanel.add(newPlanButton);
buttonPanel.add(loadPlanButton);
buttonPanel.add(deletePlanButton);
listModel = new DefaultListModel<>();
savedPlansList = new JList<>(listModel);
JScrollPane listScrollPane = new JScrollPane(savedPlansList);
add(listScrollPane, BorderLayout.CENTER);
add(buttonPanel, BorderLayout.NORTH);
add(listScrollPane, BorderLayout.CENTER);
loadSavedPlans();
}
//Creates a new floor plan
private void createNewFloorPlan() {
SwingUtilities.invokeLater(() -> {
BoothFloorPlan frame = new BoothFloorPlan();
frame.setVisible(true);
});
this.dispose();
}
//Loads existing Floorplan
private void loadSelectedFloorPlan() {
String selectedPlan = savedPlansList.getSelectedValue();
if (selectedPlan != null) {
SwingUtilities.invokeLater(() -> {
BoothFloorPlan frame = new BoothFloorPlan(selectedPlan);
frame.setVisible(true);
});
this.dispose();
} else {
JOptionPane.showMessageDialog(this, "Please select a floor plan to load.", "No Plan Selected", JOptionPane.WARNING_MESSAGE);
}
}
//Method to actually move file and load serialized data
private void loadSavedPlans() {
listModel.clear();
File folder = new File("saved_plans");
if (folder.exists() && folder.isDirectory()) {
File[] files = folder.listFiles((dir, name) -> name.toLowerCase().endsWith(".ser"));
if (files != null) {
for (File file : files) {
listModel.addElement(file.getName().replace(".ser", ""));
}
}
}
}
//deletes selected floorplan
private void deleteSelectedFloorPlan() {
String selectedPlan = savedPlansList.getSelectedValue();
if (selectedPlan != null) {
int confirm = JOptionPane.showConfirmDialog(
this,
"Are you sure you want to delete the floor plan '" + selectedPlan + "'?",
"Confirm Deletion",
JOptionPane.YES_NO_OPTION,
JOptionPane.WARNING_MESSAGE
);
if (confirm == JOptionPane.YES_OPTION) {
File fileToDelete = new File("saved_plans/" + selectedPlan + ".ser");
if (fileToDelete.delete()) {
listModel.removeElement(selectedPlan);
JOptionPane.showMessageDialog(this, "Floor plan deleted successfully.", "Deletion Successful", JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(this, "Error deleting floor plan.", "Deletion Error", JOptionPane.ERROR_MESSAGE);
}
}
} else {
JOptionPane.showMessageDialog(this, "Please select a floor plan to delete.", "No Plan Selected", JOptionPane.WARNING_MESSAGE);
}
}
//MAIN
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
LandingPage landingPage = new LandingPage();
landingPage.setVisible(true);
});
}
}