This repository has been archived by the owner on Aug 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GarageGUI.java
164 lines (128 loc) · 3.9 KB
/
GarageGUI.java
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package BicycleGarage;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import javax.swing.*;
import java.awt.FlowLayout;
import java.util.ArrayList;
@SuppressWarnings({ "serial", "unused" })
public class GarageGUI extends JFrame {
private JFrame frame;
protected JTextArea text;
private Database db;
private String pin;
private Garage gr;
private PinCodeTerminal terminal;
private BarcodeReader entry;
private BarcodeReader exit;
private BarcodePrinter printer;
private ElectronicLock entrylock, exitlock;
private ArrayList<String> pins;
public GarageGUI() {
Database db = new Database();
gr = new Garage(db);
terminal = new PinCodeTerminalTestDriver();
entry = new BarcodeReaderEntryTestDriver();
exit = new BarcodeReaderExitTestDriver();
entrylock = new ElectronicLockTestDriver("Entry");
exitlock = new ElectronicLockTestDriver("Exit");
printer = new BarcodePrinterTestDriver();
pins = new ArrayList<String>();
frame = new JFrame("Bicycle Garage");
frame.setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setBounds(100, 100, 450, 300);
frame.getContentPane().setLayout(
new FlowLayout(FlowLayout.CENTER, 5, 5));
JMenuBar menu = new JMenuBar();
frame.setJMenuBar(menu);
menu.setVisible(true);
JPanel textpanel = new JPanel();
text = new JTextArea(13, 35);
text.setEditable(false);
textpanel.add(new JScrollPane(text));
add(textpanel, BorderLayout.CENTER);
frame.add(textpanel);
textpanel.setVisible(true);
JMenu user = new JMenu("User");
menu.add(user);
JMenuItem addUsr = new ButtonAddUser(this, db);
user.add(addUsr);
JMenuItem rmvUsr = new RemoveUsrMenu(this, db, gr);
user.add(rmvUsr);
JMenu srhUsr = new JMenu("Search User");
user.add(srhUsr);
JMenuItem srhUsrBic = new SearchUserBicycleID(this, db);
srhUsr.add(srhUsrBic);
JMenuItem srhUsrSsn = new ButtonSearchSSN(this, db);
srhUsr.add(srhUsrSsn);
JMenuItem srhUsrNam = new JMenuItem("Search using name");
srhUsr.add(srhUsrNam);
JMenuItem lstUsr = new ListUsersMenu(this, db);
user.add(lstUsr);
JMenu Bicycle = new JMenu("Bicycle");
menu.add(Bicycle);
JMenuItem add = new ButtonAddBicycle(this, db);
Bicycle.add(add);
JMenuItem rmv = new ButtonRemoveBicycle(this, db, gr);
Bicycle.add(rmv);
JMenuItem srch = new JMenuItem("Search");
Bicycle.add(srch);
JMenuItem tmPk = new JMenuItem("Time parked");
Bicycle.add(tmPk);
JMenu System = new JMenu("System");
menu.add(System);
JMenuItem gnrBrc = new JMenuItem("Generate Barcode");
System.add(gnrBrc);
JMenuItem maMo = new JMenuItem("Maintenance Mode");
System.add(maMo);
JMenuItem save = new SaveDatabaseMenu(this, db, gr);
System.add(save);
JMenuItem load = new LoadDatabaseMenu(this, db, gr);
System.add(load);
JMenuItem ParkingSpots = new ParkingSpotsButton(this, db, gr);
System.add(ParkingSpots);
}
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
GarageGUI gui = new GarageGUI();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
public void entryBarcode(String code) {
if (db.getBicycle(code) != null
&& pins.contains(db.getUser(code).getPin())) {
gr.parkBic(code);
}
}
public void entryCharacter(char c) { // 3 misslyckade försök, spärrning i 30
// sek.
StringBuilder str = new StringBuilder();
str.append(c);
if (str.length() == 4) {
if (db.legitPin(str.toString())) {
pins.add(str.toString());
terminal.lightLED(PinCodeTerminal.GREEN_LED, 3);
entrylock.open(15);
} else {
terminal.lightLED(PinCodeTerminal.RED_LED, 3);
}
}
}
public void exitBarcode(String code) {
if (gr.containsBicycle(code)) {
exitlock.open(15);
}
}
public void printBarCode(String BicID) {
printer.printBarcode(BicID);
}
}
/*
* JMenuItem nbrBic = new JMenuItem("Amount of Bicycles"); Bicycle.add(nbrBic);
*/