import net.jini.core.event.EventRegistration; import net.jini.core.event.RemoteEvent; import net.jini.core.event.RemoteEventListener; import net.jini.core.event.UnknownEventException; import net.jini.core.lease.Lease; import net.jini.core.lookup.ServiceEvent; import net.jini.core.lookup.ServiceItem; import net.jini.core.lookup.ServiceRegistrar; import net.jini.core.lookup.ServiceTemplate; import net.jini.discovery.DiscoveryEvent; import net.jini.discovery.DiscoveryListener; import net.jini.discovery.LookupDiscovery; import net.jini.lease.LeaseRenewalManager; import javax.swing.*; import java.awt.*; import java.rmi.RMISecurityManager; import java.rmi.RemoteException; import java.rmi.server.UnicastRemoteObject; import java.util.ArrayList; import java.util.Iterator; import java.util.LinkedList; /** * The client application and UI logic, communicates with the HealthSpa server. * * @author Cormac Redmond -- credmond85 /at/ gmail */ public class ClientUI extends javax.swing.JFrame { /* *Global variables */ private LinkedList roomList; private LinkedList staffList; private LinkedList memberList; private HealthSpaInterface healthSpa; private String guiUsername; private String guiPassword; private boolean loggedIn; private boolean isAdmin; private ModelObject member; private eventListener eventCatcher; private int LEASE_TIME = 10 * 60 * 1000; // 10 mins LeaseRenewalManager leaseManager = new LeaseRenewalManager(); private boolean cancelled = false; eventListener cancellationListener; protected ServiceTemplate template; protected LookupDiscovery disco; // An inner class to listen for events from a lookup service (reggie) class eventListener extends UnicastRemoteObject implements RemoteEventListener { public eventListener() throws RemoteException { } // Called when an event is received for a lookup service public void notify(RemoteEvent ev) throws RemoteException, UnknownEventException { System.out.println("Got an event from: " + ev.getSource()); //Make sure its a service event if (ev instanceof ServiceEvent) { ServiceEvent sev = (ServiceEvent) ev; ServiceItem item = sev.getServiceItem(); //We can be certain that it is a HealthSpaInterface proxy healthSpa = (HealthSpaInterface) item.service; System.out.println("Got proxy from an event, about to populate it.."); //Now contact the server and populate the GUI populateGUI(); } if (ev instanceof CancellationEvent) { CancellationEvent cancellationEvent = (CancellationEvent) ev; System.out.println("Received a CancellationEvent"); //Inform user (in a new thread) about the cancellation //Why new thread? Because RemoveEventListener.notify is NOT asynchronous (see document). informCancellationGUI(cancellationEvent.getHour(), cancellationEvent.getDay(), cancellationEvent.getWeek(), cancellationEvent.getRoomCode(), cancellationEvent.getRoomName()); } else { System.out.println("Not a relevant event, " + "ignoring"); } } } //A listener used to listen for lookup services class Listener implements DiscoveryListener { public void discovered(DiscoveryEvent ev) { //An array of lookup services ServiceRegistrar[] newregs = ev.getRegistrars(); System.out.println("Discovered something..."); //For each one, see if it provides the service we want for (int i = 0; i < newregs.length; i++) { Object o = lookForService(newregs[i]); //If we have a proxy if (o != null) { healthSpa = (HealthSpaInterface) o; System.out.println("Got proxy, populating UI..."); //Talk to server an populate GUI populateGUI(); //Dont bother looking any further break; } } } public void discarded(DiscoveryEvent ev) { } } /** * Creates new form ClientUI */ public ClientUI() { initComponents(); try { //Inform the user that there may be delay...(i.e., if a service is not yet online) int n = JOptionPane.showConfirmDialog( this, "\nContacting server - the application will be usable in a moment.", "Contacting Because You're Loaded", -1); //Show hourglass cursor this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); this.loginButton.setEnabled(false); //The type of service we want to find Class[] types = { HealthSpaInterface.class }; template = new ServiceTemplate(null, types, null); // Set a security manager if (System.getSecurityManager() == null) { System.setSecurityManager(new RMISecurityManager()); } //Instantiate our event catcher eventCatcher = new eventListener(); // Only search the public group disco = new LookupDiscovery(new String[]{""}); // Install a listener disco.addDiscoveryListener(new Listener()); } catch (Exception ex) { System.err.println(ex); System.exit(0); } } // Once we've found a new lookup service, search for proxies that // implement HelloWorldServiceInterface protected Object lookForService(ServiceRegistrar lu) { Object o = null; //See if the lookup service has a service with this template try { o = lu.lookup(template); } catch (RemoteException ex) { System.err.println("Error doing lookup: " + ex.getMessage()); return null; } //If we couldn't find a matching service if (o == null) { System.err.println("No matching service."); try { System.err.println("Registering for new matching service events..."); //Ask lookup service to inform us when the service may be added registerForNewServiceEvents(lu); } catch (RemoteException ex) { System.err.println("Can't solicit events: " + ex.getMessage( )); // Discard it, so we can find it again disco.discard(lu); } finally { //This time, return null return null; } } else { System.out.println("Got a matching service: "); //Return the HealthSpaServer proxy return o; } } // Ask for events from the lookup service upon a new matching service protected void registerForNewServiceEvents(ServiceRegistrar lookupService) throws RemoteException { //Register to receive an event if any server with the 'template' attributes publishes itself lookupService.notify(template, ServiceRegistrar.TRANSITION_NOMATCH_MATCH, eventCatcher, null, LEASE_TIME); System.out.println("Registered for new matching service events."); } /** * Populates the UI components */ public void populateGUI() { try { // Get a list of rooms and staff in the Health Spa roomList = healthSpa.getRoomList(); staffList = healthSpa.getStaffList(); } catch (Exception ex) { System.err.println(ex); System.exit(0); } // Populate some drop down lists drpRoomList.addItem(new ModelObject("", "")); for (Iterator i = roomList.iterator(); i.hasNext();) { drpRoomList.addItem(i.next()); } for (Iterator i = staffList.iterator(); i.hasNext();) { drpStaffList.addItem(i.next()); } JOptionPane.showConfirmDialog( this, "\nThe application is now synchronised with the \"Because You're Loaded\" server", "Successfully contacted server", -1); System.out.println("Enabling app..."); //Allow user input... this.loginButton.setEnabled(true); this.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } // Registers the user to be informed if a certain booking is cancelled public void registerForCancellationNotfication(int hour, int day, int week, String roomCode) { EventRegistration eventRegistration; try { //Listener to use cancellationListener = new eventListener(); } catch (RemoteException ex) { ex.printStackTrace(); } try { System.out.println("Registering for cancellation notification.."); //Register... eventRegistration = healthSpa.registerForCancellationEvents(hour, day, week, roomCode, null, cancellationListener, Lease.ANY); System.out.println("Just received an EventRegistration..."); System.out.println("ID: " + eventRegistration.getID()); System.out.println("Seq number: " + eventRegistration.getSequenceNumber()); //Keep renewing lease... leaseManager.renewUntil(eventRegistration.getLease(), Lease.ANY, null); } catch (RemoteException ex) { System.err.println("Error: " + ex.getMessage()); } } // //GEN-BEGIN:initComponents private void initComponents() { pnlAddUser = new javax.swing.JPanel(); jButton1 = new javax.swing.JButton(); txtNewUserUsername = new javax.swing.JTextField(); txtNewUserPassword = new javax.swing.JTextField(); jLabel4 = new javax.swing.JLabel(); jLabel6 = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); txtNewUserName = new javax.swing.JTextField(); pnlRecordPayment = new javax.swing.JPanel(); jLabel15 = new javax.swing.JLabel(); drpMemberList = new javax.swing.JComboBox(); jLabel16 = new javax.swing.JLabel(); drpUnpaidBookings = new javax.swing.JComboBox(); btnViewBooking = new javax.swing.JButton(); pnlSetPrice = new javax.swing.JPanel(); jLabel7 = new javax.swing.JLabel(); drpRooms = new javax.swing.JComboBox(); jLabel8 = new javax.swing.JLabel(); jLabel9 = new javax.swing.JLabel(); lblCurrentPrice = new javax.swing.JLabel(); jLabel14 = new javax.swing.JLabel(); txtNewPrice = new javax.swing.JTextField(); jButton2 = new javax.swing.JButton(); pnlViewAccount = new javax.swing.JPanel(); jLabel17 = new javax.swing.JLabel(); lblAccountID = new javax.swing.JLabel(); jLabel19 = new javax.swing.JLabel(); drpOldBookings = new javax.swing.JComboBox(); btnDetails = new javax.swing.JButton(); jLabel18 = new javax.swing.JLabel(); drpNewBookings = new javax.swing.JComboBox(); lblName = new javax.swing.JLabel(); jLabel20 = new javax.swing.JLabel(); btnCancelBooking = new javax.swing.JButton(); pnlChangePassword = new javax.swing.JPanel(); jLabel21 = new javax.swing.JLabel(); jLabel22 = new javax.swing.JLabel(); jLabel23 = new javax.swing.JLabel(); txtCurrentUsername = new javax.swing.JTextField(); btnChangePassword = new javax.swing.JButton(); txtCurrentPassword = new javax.swing.JPasswordField(); txtNewPassword = new javax.swing.JPasswordField(); jPanel1 = new javax.swing.JPanel(); jLabel12 = new javax.swing.JLabel(); jLabel13 = new javax.swing.JLabel(); txtUsername = new javax.swing.JTextField(); txtPassword = new javax.swing.JPasswordField(); loginButton = new javax.swing.JButton(); logoutButton = new javax.swing.JButton(); loginStatus = new javax.swing.JLabel(); jLabel1 = new javax.swing.JLabel(); jTabbedPane1 = new javax.swing.JTabbedPane(); jPanel3 = new javax.swing.JPanel(); drpRoomList = new javax.swing.JComboBox(); jScrollPane5 = new javax.swing.JScrollPane(); tblRoomNames = new javax.swing.JTable(); jLabel10 = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); jScrollPane3 = new javax.swing.JScrollPane(); tblRoomTimetable = new javax.swing.JTable(); drpTimePeriod = new javax.swing.JComboBox(); jLabel25 = new javax.swing.JLabel(); drpRoomWeek = new javax.swing.JComboBox(); lblNote = new javax.swing.JLabel(); jPanel2 = new javax.swing.JPanel(); jScrollPane1 = new javax.swing.JScrollPane(); jTable1 = new javax.swing.JTable(); jScrollPane2 = new javax.swing.JScrollPane(); tblStaffTimetable = new javax.swing.JTable(); jLabel11 = new javax.swing.JLabel(); drpStaffList = new javax.swing.JComboBox(); jLabel24 = new javax.swing.JLabel(); drpStaffWeek = new javax.swing.JComboBox(); jSeparator1 = new javax.swing.JSeparator(); jLabel3 = new javax.swing.JLabel(); tpUserPanel = new javax.swing.JTabbedPane(); jButton1.setText("Add User"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jLabel4.setText("Password:"); jLabel6.setText("Username:"); jLabel5.setText("Name:"); javax.swing.GroupLayout pnlAddUserLayout = new javax.swing.GroupLayout(pnlAddUser); pnlAddUser.setLayout(pnlAddUserLayout); pnlAddUserLayout.setHorizontalGroup( pnlAddUserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlAddUserLayout.createSequentialGroup() .addGroup(pnlAddUserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlAddUserLayout.createSequentialGroup() .addGap(20, 20, 20) .addGroup(pnlAddUserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlAddUserLayout.createSequentialGroup() .addComponent(jLabel4) .addGap(11, 11, 11) .addComponent(txtNewUserPassword, javax.swing.GroupLayout.DEFAULT_SIZE, 66, Short.MAX_VALUE)) .addGroup(pnlAddUserLayout.createSequentialGroup() .addComponent(jLabel6) .addGap(9, 9, 9) .addComponent(txtNewUserUsername, javax.swing.GroupLayout.DEFAULT_SIZE, 66, Short.MAX_VALUE)) .addGroup(pnlAddUserLayout.createSequentialGroup() .addComponent(jLabel5) .addGap(30, 30, 30) .addComponent(txtNewUserName, javax.swing.GroupLayout.DEFAULT_SIZE, 66, Short.MAX_VALUE)))) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlAddUserLayout.createSequentialGroup() .addContainerGap(70, Short.MAX_VALUE) .addComponent(jButton1))) .addContainerGap()) ); pnlAddUserLayout.setVerticalGroup( pnlAddUserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlAddUserLayout.createSequentialGroup() .addContainerGap() .addGroup(pnlAddUserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel5) .addComponent(txtNewUserName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(pnlAddUserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel6) .addComponent(txtNewUserUsername, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(pnlAddUserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel4) .addComponent(txtNewUserPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(14, 14, 14) .addComponent(jButton1) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); jLabel15.setText("Select a user:"); drpMemberList.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { drpMemberListActionPerformed(evt); } }); jLabel16.setText("Unpaid Bookings:"); btnViewBooking.setText("View"); btnViewBooking.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnViewBookingActionPerformed(evt); } }); javax.swing.GroupLayout pnlRecordPaymentLayout = new javax.swing.GroupLayout(pnlRecordPayment); pnlRecordPayment.setLayout(pnlRecordPaymentLayout); pnlRecordPaymentLayout.setHorizontalGroup( pnlRecordPaymentLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlRecordPaymentLayout.createSequentialGroup() .addContainerGap() .addGroup(pnlRecordPaymentLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(btnViewBooking) .addGroup(pnlRecordPaymentLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addComponent(drpMemberList, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(drpUnpaidBookings, javax.swing.GroupLayout.Alignment.LEADING, 0, 160, Short.MAX_VALUE) .addComponent(jLabel15, javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel16, javax.swing.GroupLayout.Alignment.LEADING))) .addContainerGap(19, Short.MAX_VALUE)) ); pnlRecordPaymentLayout.setVerticalGroup( pnlRecordPaymentLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlRecordPaymentLayout.createSequentialGroup() .addContainerGap() .addComponent(jLabel15) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(drpMemberList, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(16, 16, 16) .addComponent(jLabel16) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(drpUnpaidBookings, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(btnViewBooking) .addContainerGap(75, Short.MAX_VALUE)) ); jLabel7.setText("Select a room:"); drpRooms.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { drpRoomsActionPerformed(evt); } }); jLabel9.setText("Current Price:"); lblCurrentPrice.setBackground(new java.awt.Color(255, 51, 204)); lblCurrentPrice.setText("jLabel14"); jLabel14.setText("New Price:"); jButton2.setText("Set New Price"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); javax.swing.GroupLayout pnlSetPriceLayout = new javax.swing.GroupLayout(pnlSetPrice); pnlSetPrice.setLayout(pnlSetPriceLayout); pnlSetPriceLayout.setHorizontalGroup( pnlSetPriceLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlSetPriceLayout.createSequentialGroup() .addContainerGap() .addGroup(pnlSetPriceLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlSetPriceLayout.createSequentialGroup() .addGroup(pnlSetPriceLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel8) .addGroup(pnlSetPriceLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false) .addComponent(drpRooms, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(javax.swing.GroupLayout.Alignment.LEADING, pnlSetPriceLayout.createSequentialGroup() .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))) .addContainerGap(54, Short.MAX_VALUE)) .addGroup(pnlSetPriceLayout.createSequentialGroup() .addGroup(pnlSetPriceLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlSetPriceLayout.createSequentialGroup() .addComponent(jLabel9) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(lblCurrentPrice)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlSetPriceLayout.createSequentialGroup() .addComponent(jLabel14) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(txtNewPrice, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap()) .addGroup(pnlSetPriceLayout.createSequentialGroup() .addComponent(jButton2) .addContainerGap(24, Short.MAX_VALUE)))) ); pnlSetPriceLayout.setVerticalGroup( pnlSetPriceLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlSetPriceLayout.createSequentialGroup() .addContainerGap() .addComponent(jLabel7) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(drpRooms, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(9, 9, 9) .addGroup(pnlSetPriceLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel8) .addGroup(pnlSetPriceLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel9) .addComponent(lblCurrentPrice))) .addGap(16, 16, 16) .addGroup(pnlSetPriceLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel14) .addComponent(txtNewPrice, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton2) .addContainerGap(23, Short.MAX_VALUE)) ); jLabel17.setText("Account ID:"); lblAccountID.setText("jLabel18"); jLabel19.setText("Paid bookings:"); btnDetails.setText("Details"); btnDetails.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnDetailsActionPerformed(evt); } }); jLabel18.setText("Unpaid Bookings:"); lblName.setText("name"); jLabel20.setText("Name:"); btnCancelBooking.setText("Cancel Booking!"); btnCancelBooking.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnCancelBookingActionPerformed(evt); } }); javax.swing.GroupLayout pnlViewAccountLayout = new javax.swing.GroupLayout(pnlViewAccount); pnlViewAccount.setLayout(pnlViewAccountLayout); pnlViewAccountLayout.setHorizontalGroup( pnlViewAccountLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlViewAccountLayout.createSequentialGroup() .addContainerGap() .addGroup(pnlViewAccountLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlViewAccountLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jLabel19) .addComponent(jLabel18) .addGroup(pnlViewAccountLayout.createSequentialGroup() .addComponent(jLabel17) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(lblAccountID)) .addGroup(pnlViewAccountLayout.createSequentialGroup() .addComponent(btnDetails) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(btnCancelBooking)) .addComponent(drpNewBookings, 0, 167, Short.MAX_VALUE) .addComponent(drpOldBookings, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(pnlViewAccountLayout.createSequentialGroup() .addComponent(jLabel20) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(lblName))) .addContainerGap(26, Short.MAX_VALUE)) ); pnlViewAccountLayout.setVerticalGroup( pnlViewAccountLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlViewAccountLayout.createSequentialGroup() .addContainerGap() .addGroup(pnlViewAccountLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel20) .addComponent(lblName)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(pnlViewAccountLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel17) .addComponent(lblAccountID)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel19) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(drpOldBookings, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(14, 14, 14) .addComponent(jLabel18) .addGap(7, 7, 7) .addComponent(drpNewBookings, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(pnlViewAccountLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(btnDetails) .addComponent(btnCancelBooking)) .addContainerGap()) ); jLabel21.setText("Username:"); jLabel22.setText("Password:"); jLabel23.setText("New password:"); btnChangePassword.setText("Change Password"); btnChangePassword.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { btnChangePasswordActionPerformed(evt); } }); javax.swing.GroupLayout pnlChangePasswordLayout = new javax.swing.GroupLayout(pnlChangePassword); pnlChangePassword.setLayout(pnlChangePasswordLayout); pnlChangePasswordLayout.setHorizontalGroup( pnlChangePasswordLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlChangePasswordLayout.createSequentialGroup() .addContainerGap() .addGroup(pnlChangePasswordLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addComponent(btnChangePassword) .addGroup(pnlChangePasswordLayout.createSequentialGroup() .addGroup(pnlChangePasswordLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel23) .addComponent(jLabel22) .addComponent(jLabel21)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(pnlChangePasswordLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(txtCurrentPassword, javax.swing.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE) .addComponent(txtCurrentUsername, javax.swing.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlChangePasswordLayout.createSequentialGroup() .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(txtNewPassword, javax.swing.GroupLayout.DEFAULT_SIZE, 80, Short.MAX_VALUE))))) .addGap(18, 18, 18)) ); pnlChangePasswordLayout.setVerticalGroup( pnlChangePasswordLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlChangePasswordLayout.createSequentialGroup() .addContainerGap() .addGroup(pnlChangePasswordLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel21) .addComponent(txtCurrentUsername, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(pnlChangePasswordLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel22) .addComponent(txtCurrentPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(pnlChangePasswordLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel23) .addComponent(txtNewPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(15, 15, 15) .addComponent(btnChangePassword) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setResizable(false); jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Login")); jLabel12.setText("Username:"); jLabel13.setText("Password:"); loginButton.setText("Login"); loginButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { loginButtonActionPerformed(evt); } }); logoutButton.setText("Logout"); logoutButton.setEnabled(false); logoutButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { logoutButtonActionPerformed(evt); } }); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jLabel13) .addComponent(jLabel12)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(txtUsername) .addComponent(txtPassword, javax.swing.GroupLayout.DEFAULT_SIZE, 95, Short.MAX_VALUE))) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(loginButton) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 29, Short.MAX_VALUE) .addComponent(logoutButton)) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel12) .addComponent(txtUsername, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel13) .addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(loginButton) .addComponent(logoutButton))) ); loginStatus.setFont(new java.awt.Font("Arial", 0, 10)); loginStatus.setText("Not logged in."); jLabel1.setFont(new java.awt.Font("Tahoma", 0, 8)); jLabel1.setText("(You must be logged in to book a session)"); jTabbedPane1.setBorder(javax.swing.BorderFactory.createTitledBorder("Health Spa")); drpRoomList.setModel(new javax.swing.DefaultComboBoxModel(new String[]{""})); drpRoomList.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { drpRoomListActionPerformed(evt); } }); tblRoomNames.setModel(new javax.swing.table.DefaultTableModel( new Object[][] { }, new String[] { "Room" } )); jScrollPane5.setViewportView(tblRoomNames); jLabel10.setText("Room Timetable for:"); jLabel2.setText("at"); tblRoomTimetable.setModel(new javax.swing.table.DefaultTableModel( new Object[][] { }, new String[] { "Mon", "Tue", "Wed", "Thur", "Fri", "Sat", "Sunday" } )); tblRoomTimetable.setCellSelectionEnabled(true); tblRoomTimetable.setMaximumSize(new java.awt.Dimension(14, 16)); tblRoomTimetable.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { tblRoomTimetableMouseClicked(evt); } }); jScrollPane3.setViewportView(tblRoomTimetable); drpTimePeriod.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"8-9", "9-10", "10-11", "11-12", "12-1", "1-2", "2-3", "3-4", "4-5", "5-6"})); drpTimePeriod.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { drpRoomListActionPerformed(evt); } }); jLabel25.setText("in"); drpRoomWeek.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"Current Week", "Next Week"})); drpRoomWeek.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { drpRoomWeekActionPerformed(evt); } }); lblNote.setText("Note: If you would like to be informed of a cancellation of a particular timeslot, click on \"BOOKED\" for further details."); javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); jPanel3.setLayout(jPanel3Layout); jPanel3Layout.setHorizontalGroup( jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup() .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane5, 0, 0, Short.MAX_VALUE) .addComponent(jLabel10)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup() .addComponent(drpRoomList, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(drpTimePeriod, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(14, 14, 14) .addComponent(jLabel25) .addGap(12, 12, 12) .addComponent(drpRoomWeek, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 457, Short.MAX_VALUE)) .addContainerGap(13, Short.MAX_VALUE)) .addGroup(jPanel3Layout.createSequentialGroup() .addComponent(lblNote) .addContainerGap(16, Short.MAX_VALUE)))) ); jPanel3Layout.setVerticalGroup( jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(drpRoomList, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel2) .addComponent(drpTimePeriod, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel10) .addComponent(jLabel25) .addComponent(drpRoomWeek, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false) .addComponent(jScrollPane5, 0, 0, Short.MAX_VALUE) .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 9, Short.MAX_VALUE) .addComponent(lblNote) .addContainerGap()) ); jTabbedPane1.addTab("Rooms", jPanel3); jScrollPane1.setFont(new java.awt.Font("Tahoma", 3, 12)); jTable1.setFont(new java.awt.Font("Tahoma", 1, 11)); jTable1.setModel(new javax.swing.table.DefaultTableModel( new Object[][] { {"8 - 9"}, {"9 - 10"}, {"10 - 11"}, {"11 - 12"}, {"12 - 1"}, {"1 - 2"}, {"2 - 3"}, {"3 - 4"}, {"4 - 5"}, {"5 - 6"} }, new String[] { "Time" } ) { boolean[] canEdit = new boolean[] { false }; public boolean isCellEditable(int rowIndex, int columnIndex) { return canEdit[columnIndex]; } }); jTable1.setAutoscrolls(false); jScrollPane1.setViewportView(jTable1); jScrollPane2.setBorder(null); tblStaffTimetable.setModel(new javax.swing.table.DefaultTableModel( new Object[][] { {null, null, null, null, null, null, null}, {null, null, null, null, null, null, null}, {null, null, null, null, null, null, null}, {null, null, null, null, null, null, null}, {null, null, null, null, null, null, null}, {null, null, null, null, null, null, null}, {null, null, null, null, null, null, null}, {null, null, null, null, null, null, null}, {null, null, null, null, null, null, null}, {null, null, null, null, null, null, null} }, new String[] { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" } ) { boolean[] canEdit = new boolean[] { false, false, false, false, false, false, false }; public boolean isCellEditable(int rowIndex, int columnIndex) { return canEdit[columnIndex]; } }); tblStaffTimetable.setAutoscrolls(false); jScrollPane2.setViewportView(tblStaffTimetable); jLabel11.setText("Staff Timetable for:"); drpStaffList.setModel(new javax.swing.DefaultComboBoxModel(new String[]{""})); drpStaffList.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { drpStaffListActionPerformed(evt); } }); jLabel24.setText("in"); drpStaffWeek.setModel(new javax.swing.DefaultComboBoxModel(new String[]{"Current Week", "Next Week"})); drpStaffWeek.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { drpStaffListActionPerformed(evt); } }); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 506, Short.MAX_VALUE)) .addGroup(jPanel2Layout.createSequentialGroup() .addComponent(jLabel11) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(drpStaffList, javax.swing.GroupLayout.PREFERRED_SIZE, 117, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(19, 19, 19) .addComponent(jLabel24, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(drpStaffWeek, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap()) ); jPanel2Layout.setVerticalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel11) .addComponent(drpStaffList, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(drpStaffWeek, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jLabel24)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 184, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 185, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(44, Short.MAX_VALUE)) ); jTabbedPane1.addTab("Staff", jPanel2); jSeparator1.setOrientation(javax.swing.SwingConstants.VERTICAL); jLabel3.setFont(new java.awt.Font("Tahoma", 1, 24)); jLabel3.setText("Because You're Loaded - Health Spa"); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addComponent(loginStatus) .addComponent(jLabel1) .addComponent(tpUserPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 221, javax.swing.GroupLayout.PREFERRED_SIZE)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(105, 105, 105) .addComponent(jLabel3)) .addGroup(layout.createSequentialGroup() .addGap(24, 24, 24) .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 604, Short.MAX_VALUE))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jTabbedPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 324, javax.swing.GroupLayout.PREFERRED_SIZE)) .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 456, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(loginStatus) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(tpUserPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 262, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap()) ); pack(); }// //GEN-END:initComponents /* *Handler for when a user chooses to cancel a booking */ private void btnCancelBookingActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnCancelBookingActionPerformed {//GEN-HEADEREND:event_btnCancelBookingActionPerformed //The booking they want to cancel Booking tempBooking = (Booking) drpNewBookings.getSelectedItem(); //Confirm int n = JOptionPane.showConfirmDialog( this, "Do you want to cancel ths reservation for " + Days.getDay(tempBooking.getDay()) + "(" + Days.getWeek(tempBooking.getWeek()) + ") " + "at " + Days.getHour(tempBooking.getHour()) + "?", "Cancellation", JOptionPane.YES_NO_OPTION); if (n == 0) { try { System.out.println("About to cancel booking..."); //Cancel it if (healthSpa.cancelBooking(tempBooking, member.getCode(), guiUsername, guiPassword) == 0) { JOptionPane.showMessageDialog(this, "The booking was successfully cancelled.", "Cancellation confirmed", JOptionPane.INFORMATION_MESSAGE); //Remove from visible list drpNewBookings.removeItemAt(drpNewBookings.getSelectedIndex()); //Call event handler, which in turn will make the client's data up to date drpRoomListActionPerformed(null); //Cop-out way of updating client data (I am no swing expert) setUpUserAccountInfo(); } else { JOptionPane.showMessageDialog(this, "There was an error cancelling the booking", "Error cancelling room", JOptionPane.ERROR_MESSAGE); } } catch (RemoteException ex) { ex.printStackTrace(); } } }//GEN-LAST:event_btnCancelBookingActionPerformed private void drpRoomWeekActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_drpRoomWeekActionPerformed {//GEN-HEADEREND:event_drpRoomWeekActionPerformed drpRoomListActionPerformed(null); }//GEN-LAST:event_drpRoomWeekActionPerformed /* * Event handler to handle a password change */ private void btnChangePasswordActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnChangePasswordActionPerformed {//GEN-HEADEREND:event_btnChangePasswordActionPerformed //Make sure all relevant data was entered if (txtCurrentUsername.getText().equals("") || new String(txtCurrentPassword.getPassword()).equals("") || new String(txtNewPassword.getPassword()).equals("")) { JOptionPane.showMessageDialog( this, "You must fill in each field.", "Booking Information", JOptionPane.ERROR_MESSAGE); } else { int result = -1; try { //Attempt to change the password. result = healthSpa.changePassword(member.getCode(), txtCurrentUsername.getText(), new String(txtCurrentPassword.getPassword()), new String(txtNewPassword.getPassword())); } catch (RemoteException ex) { ex.printStackTrace(); } //Inform, accordingly. if (result == 0) { JOptionPane.showMessageDialog( this, "Password successfully changed.", "Password Changed", JOptionPane.INFORMATION_MESSAGE); } else { JOptionPane.showMessageDialog( this, "An error occured - make sure you have the correct username and password.", "Password Change Error", JOptionPane.ERROR_MESSAGE); } }//GEN-LAST:event_btnChangePasswordActionPerformed } // An event handler to display to the user details of an unpaid booking. private void btnDetailsActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnDetailsActionPerformed {//GEN-HEADEREND:event_btnDetailsActionPerformed Booking tempBooking = (Booking) drpNewBookings.getSelectedItem(); JOptionPane.showMessageDialog( this, "Booked by you for " + Days.getDay(tempBooking.getDay()) + "(" + Days.getWeek(tempBooking.getWeek()) + ") " + "at " + Days.getHour(tempBooking.getHour()) + ".", "Booking Information", JOptionPane.INFORMATION_MESSAGE); }//GEN-LAST:event_btnDetailsActionPerformed // An event handler that can only be used by the admin. Allows the recording of a payment, // after the admin selects a user and an unpaid booking. private void btnViewBookingActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnViewBookingActionPerformed {//GEN-HEADEREND:event_btnViewBookingActionPerformed Booking tempBooking = (Booking) drpUnpaidBookings.getSelectedItem(); int n = JOptionPane.showConfirmDialog( this, "Booking for " + Days.getDay(tempBooking.getDay()) + "(" + Days.getWeek(tempBooking.getWeek()) + ") " + "at " + Days.getHour(tempBooking.getHour()) + "." + "\nWould you like to confirm payment?", "Record a Payment", JOptionPane.YES_NO_OPTION); if (n == 0) { try { //Try to record the booking healthSpa.recordPayment(guiUsername, guiPassword, memberList.get(drpMemberList.getSelectedIndex()).getCode(), tempBooking.getBookingNo()); } catch (RemoteException ex) { ex.printStackTrace(); } //Call this handler to update the original list, to keep viewed data consistent. //Probably frowned upon to call event handlers like this, but swing is too messy otherwise. drpMemberListActionPerformed(null); } }//GEN-LAST:event_btnViewBookingActionPerformed // An event handler that displays the unpaid booking records of a user. // Only used by the admin. private void drpMemberListActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_drpMemberListActionPerformed {//GEN-HEADEREND:event_drpMemberListActionPerformed if (loggedIn == true) { ArrayList allUserBookings; try { //Clear list drpUnpaidBookings.removeAllItems(); //Get booking info allUserBookings = healthSpa.getMemberBookingInfo(guiUsername, guiPassword, memberList.get(drpMemberList.getSelectedIndex()).getCode()); //Display for (Iterator i = allUserBookings.iterator(); i.hasNext();) { Booking tempBooking = i.next(); if (tempBooking.isPaid() == false) { drpUnpaidBookings.addItem(tempBooking); } } } catch (RemoteException ex) { ex.printStackTrace(); } } }//GEN-LAST:event_drpMemberListActionPerformed //An event handler to change the price of a room. //Can only be used by the admin. private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton2ActionPerformed {//GEN-HEADEREND:event_jButton2ActionPerformed try { double newPrice = Double.parseDouble(txtNewPrice.getText()); try { healthSpa.setPrice(guiUsername, guiPassword, ((ModelObject) drpRooms.getSelectedItem()).getCode(), newPrice); roomList = healthSpa.getRoomList(); drpRoomsActionPerformed(null); } catch (RemoteException ex) { ex.printStackTrace(); } JOptionPane.showMessageDialog(this, "Price changed successfully.", "New Price Change", JOptionPane.INFORMATION_MESSAGE); } //Makes sure the input is a number catch (NumberFormatException ex) { JOptionPane.showMessageDialog(this, "The new price supplied is not a number", "New Price Error", JOptionPane.ERROR_MESSAGE); } }//GEN-LAST:event_jButton2ActionPerformed // Updates a room price label private void drpRoomsActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_drpRoomsActionPerformed {//GEN-HEADEREND:event_drpRoomsActionPerformed if (loggedIn == true) { lblCurrentPrice.setText((roomList.get(drpRooms.getSelectedIndex()).getData())); } }//GEN-LAST:event_drpRoomsActionPerformed // An event handler to add a new user. // Can only be used by an admin. private void jButton1ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton1ActionPerformed {//GEN-HEADEREND:event_jButton1ActionPerformed //Make sure all relevenat input provided. if (txtNewUserUsername.getText().equals("") || txtNewUserPassword.getText().equals("") || txtNewUserName.getText().equals("")) { JOptionPane.showMessageDialog(this, "You must provide all details to add a user.", "Error Adding New User", JOptionPane.ERROR_MESSAGE); } else { try { //Attempt to add, and check results. int result = healthSpa.addUser(guiUsername, guiPassword, txtNewUserUsername.getText(), txtNewUserPassword.getText(), txtNewUserName.getText()); if (result == 0) { JOptionPane.showMessageDialog(this, "User added successfully.", "New User Added", JOptionPane.INFORMATION_MESSAGE); txtNewUserName.setText(""); txtNewUserUsername.setText(""); txtNewUserPassword.setText(""); } else if (result == -1) { JOptionPane.showMessageDialog(this, "There was an unknown error adding the new user.", "Error Adding New User", JOptionPane.ERROR_MESSAGE); } else if (result == -2) { JOptionPane.showMessageDialog(this, "That username already exists.", "Error Adding New User", JOptionPane.ERROR_MESSAGE); } } catch (RemoteException ex) { ex.printStackTrace(); } } }//GEN-LAST:event_jButton1ActionPerformed // A complicated event handler which is called when the user clicks to book a room, and then // provides them with a list of available (for that time period) staff members. // Also allows user to choose to be informed of the cancellation of an already reserved room. private void tblRoomTimetableMouseClicked(java.awt.event.MouseEvent evt)//GEN-FIRST:event_tblRoomTimetableMouseClicked {//GEN-HEADEREND:event_tblRoomTimetableMouseClicked if (drpRoomList.getSelectedItem().toString() != null) { boolean viewingAll; viewingAll = drpRoomList.getSelectedItem().toString().equals(""); int row = tblRoomTimetable.getSelectedRow(); int column = tblRoomTimetable.getSelectedColumn(); if (loggedIn) { if (tblRoomTimetable.getValueAt(row, column).toString().equals("BOOKED")) { int n = JOptionPane.showConfirmDialog( this, "This room is already reserved." + "\nWould you like to be informed in the event of a cancellation?", "Room already reserved", JOptionPane.YES_NO_OPTION); if (n == 0) { System.out.println("About to register for cancellation event..."); String roomCode; if (viewingAll) { ModelObject temp = roomList.get(row); roomCode = temp.getCode(); } else { roomCode = ((ModelObject) drpRoomList.getSelectedItem()).getCode(); } this.registerForCancellationNotfication(drpTimePeriod.getSelectedIndex(), column, drpRoomWeek.getSelectedIndex(), roomCode); System.out.println("Just registered for cancellation events..."); } } else if (tblRoomTimetable.getValueAt(row, column).toString().equals("-click-")) { String roomCode; String price; if (viewingAll) { ModelObject temp = roomList.get(row); roomCode = temp.getCode(); price = temp.getData(); } else { roomCode = ((ModelObject) drpRoomList.getSelectedItem()).getCode(); price = ((ModelObject) drpRoomList.getSelectedItem()).getData(); } try { //Get a list of the available staff for this time period LinkedList availableStaff = healthSpa.getStaffAvailableList(drpTimePeriod.getSelectedIndex(), column, drpRoomWeek.getSelectedIndex()); availableStaff.addFirst(new ModelObject("", null)); //Display and receive available staff members. ModelObject s = (ModelObject) JOptionPane.showInputDialog( this, "Price: " + price + "\n\nThe following staff members are available at this time period.\n" + "Please choose: ", "Book a staff member", JOptionPane.PLAIN_MESSAGE, null, availableStaff.toArray(), ""); if (s != null) { //Try to book room if (healthSpa.makeBooking(roomCode, member.getCode(), s.getCode(), guiUsername, guiPassword, drpTimePeriod.getSelectedIndex(), column, drpRoomWeek.getSelectedIndex()) == 0) { JOptionPane.showMessageDialog(this, "The room was successfully booked.", "Booking confirmed", JOptionPane.INFORMATION_MESSAGE); } else { JOptionPane.showMessageDialog(this, "There was an error booking room", "Error booking room", JOptionPane.ERROR_MESSAGE); } } } catch (RemoteException ex) { ex.printStackTrace(); } //Call event handler, which in turn will make the client's data up to date drpRoomListActionPerformed(null); } if (loggedIn && !isAdmin) { //Cop-out way of updating client data (I am no swing expert) setUpUserAccountInfo(); } } //Occurs when a person is not logged in, and tries to book a room. else { JOptionPane.showMessageDialog(this, "You must be logged in to book a room.", "Not logged in", JOptionPane.ERROR_MESSAGE); } } }//GEN-LAST:event_tblRoomTimetableMouseClicked //An event handler updates the staff timetable, depending on who the user selected. private void drpStaffListActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_drpStaffListActionPerformed {//GEN-HEADEREND:event_drpStaffListActionPerformed boolean[][] tempStaffTimetable; ModelObject selectedStaff; if (drpStaffList.getSelectedIndex() != 0) { selectedStaff = (ModelObject) drpStaffList.getSelectedItem(); try { //Get the roster for this member of staff tempStaffTimetable = healthSpa.getStaffRoster(selectedStaff.getCode(), drpStaffWeek.getSelectedIndex()); //Create the TableModel ClientUITimetableTableModel staffTimetable = new ClientUITimetableTableModel(tempStaffTimetable, tempStaffTimetable.length, "N/A", "Free"); //Add to table tblStaffTimetable.setModel(staffTimetable); } catch (RemoteException ex) { ex.printStackTrace(); } } }//GEN-LAST:event_drpStaffListActionPerformed // An event handler which updates the Room timetable view, depending on what the user selected // (i.e., all or single rooms), etc. private void drpRoomListActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_drpRoomListActionPerformed {//GEN-HEADEREND:event_drpRoomListActionPerformed try { if (drpRoomList.getSelectedItem() instanceof ModelObject) { ModelObject a = (ModelObject) drpRoomList.getSelectedItem(); if (a.getCode().equals("")) { boolean[][] tempTimetable; boolean[] temp; tempTimetable = new boolean[roomList.size()][7]; int counter = 0; for (Iterator r = roomList.iterator(); r.hasNext();) { ModelObject tempRoom = r.next(); //Get the timetable temp = healthSpa.getRoomTimetableForPeriod(tempRoom.getCode(), drpTimePeriod.getSelectedIndex(), drpRoomWeek.getSelectedIndex()); for (int i = 0; i < temp.length; i++) { tempTimetable[counter][i] = temp[i]; } counter++; } //Make and set TableModel ClientUITimetableTableModel periodTimetable = new ClientUITimetableTableModel(tempTimetable, tempTimetable.length); tblRoomTimetable.setModel(periodTimetable); tblRoomNames.setModel(new ClientUITimetableTableModel(drpRoomList, roomList.size())); } //Occurs when a single room is selected else { boolean[] tempTimetable = healthSpa.getRoomTimetableForPeriod(a.getCode(), drpTimePeriod.getSelectedIndex(), drpRoomWeek.getSelectedIndex()); ClientUITimetableTableModel periodTimetable = new ClientUITimetableTableModel(tempTimetable, 1); Object[] tempObject = new Object[1]; tempObject[0] = drpRoomList.getSelectedItem(); tblRoomNames.setModel(new ClientUITimetableTableModel(tempObject, 1)); tblRoomTimetable.setModel(periodTimetable); } } //Occurs when no room is selected, so blank it. else { boolean[] temp = new boolean[0]; tblRoomTimetable.setModel(new ClientUITimetableTableModel(temp, 0)); tblRoomNames.setModel(new ClientUITimetableTableModel(new Object[0], 0)); } } catch (RemoteException ex) { ex.printStackTrace(); } drpStaffListActionPerformed(null); }//GEN-LAST:event_drpRoomListActionPerformed // Occurs when the user logs out private void logoutButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_logoutButtonActionPerformed {//GEN-HEADEREND:event_logoutButtonActionPerformed txtUsername.setEnabled(true); txtPassword.setEnabled(true); loginButton.setEnabled(true); logoutButton.setEnabled(false); guiUsername = null; guiPassword = null; loggedIn = false; isAdmin = false; member = null; loginStatus.setText("Not logged in."); tpUserPanel.removeAll(); }//GEN-LAST:event_logoutButtonActionPerformed // Occurs when a user logs in. The semantics depend on whether the user is an admin or normal user. private void loginButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_loginButtonActionPerformed {//GEN-HEADEREND:event_loginButtonActionPerformed if (!(txtUsername.getText().equals("") && new String(txtPassword.getPassword()).equals(""))) { txtUsername.setEnabled(false); txtPassword.setEnabled(false); loginButton.setEnabled(false); try { member = healthSpa.userLogin(txtUsername.getText(), new String(String.copyValueOf(txtPassword.getPassword()))); } catch (RemoteException ex) { ex.printStackTrace(); } if (member != null) { try { //If the user is admin, then populate and display certain panels, etc if (healthSpa.isUserAdmin(member.getCode())) { guiUsername = txtUsername.getText(); guiPassword = String.copyValueOf(txtPassword.getPassword()); memberList = healthSpa.getMemberList(guiUsername, guiPassword); isAdmin = true; logoutButton.setEnabled(true); loginStatus.setText("Logged in as administrator."); drpRooms.removeAllItems(); //Populate some lists for (Iterator i = roomList.iterator(); i.hasNext();) { drpRooms.addItem(i.next()); } drpMemberList.removeAllItems(); for (Iterator i = memberList.iterator(); i.hasNext();) { ModelObject tempMember = i.next(); drpMemberList.addItem("(" + tempMember.getCode() + ")" + tempMember.getName()); } tpUserPanel.removeAll(); tpUserPanel.add(pnlAddUser, "Add User"); tpUserPanel.add(pnlSetPrice, "Set Prices"); tpUserPanel.add(pnlRecordPayment, "Record Payment"); loggedIn = true; } //Otherwise, display the normal user's controls else { guiUsername = txtUsername.getText(); guiPassword = String.copyValueOf(txtPassword.getPassword()); logoutButton.setEnabled(true); loginStatus.setText("Logged in as user."); tpUserPanel.add(pnlViewAccount, "Account Info"); tpUserPanel.add(pnlChangePassword, "Change Password"); loggedIn = true; //Todo - show up a/c info stuff isAdmin = false; setUpUserAccountInfo(); } } catch (RemoteException ex) { ex.printStackTrace(); } } //Happens if a login is incorrect. else { txtUsername.setEnabled(true); txtPassword.setEnabled(true); loginButton.setEnabled(true); JOptionPane.showMessageDialog(this, "Username or password incorrect - please try again.", "Invalid User", JOptionPane.ERROR_MESSAGE); } } }//GEN-LAST:event_loginButtonActionPerformed // Calls by RemoteEventListener's notify public void informCancellationGUI(int hour, int day, int week, String roomCode, String roomName) { //Start new thread to inform user (neccessary, because notify is blocking) cancellationInformThread p = new cancellationInformThread(hour, day, week, roomCode, roomName); p.start(); } // Thread to inform user of a cancellation class cancellationInformThread extends Thread { int hour, day, week; String roomCode, roomName; cancellationInformThread(int hour, int day, int week, String roomCode, String roomName) { this.hour = hour; this.day = day; this.week = week; this.roomCode = roomCode; this.roomName = roomName; } public void run() { String dayS = Days.getDay(day); String hourS = Days.getHour(hour); //String weekS = Days.getWeek(week); informOfCancellation(hour, day, week, roomCode, roomName); } } public void informOfCancellation(int hour, int day, int week, String roomCode, String roomName) { int result = JOptionPane.showConfirmDialog(this, "A reservation for the room " + roomName + " (" + roomCode + ") at " + Days.getHour(hour) + " on " + Days.getDay(day) + "(" + Days.getWeek(week) + ")" + "has been cancelled. \n You asked to be informed of a cancellation. \nWould you like to book this slot now?", "Cancellation", JOptionPane.YES_NO_OPTION); //If they want to book it... if (result == 0) { try { //Get a list of the available staff for this time period LinkedList availableStaff = healthSpa.getStaffAvailableList(hour, day, week); availableStaff.addFirst(new ModelObject("", null)); //Display and receive available staff members. ModelObject s = (ModelObject) JOptionPane.showInputDialog( this, "The following staff members are available at this time period.\n" + "Please choose: ", "Book a staff member", JOptionPane.PLAIN_MESSAGE, null, availableStaff.toArray(), ""); if (s != null) { //Try to book room if (healthSpa.makeBooking(roomCode, member.getCode(), s.getCode(), guiUsername, guiPassword, hour, day, week) == 0) { JOptionPane.showMessageDialog(this, "The room was successfully booked.", "Booking confirmed", JOptionPane.INFORMATION_MESSAGE); } else { JOptionPane.showMessageDialog(this, "The room has already been re-booked.", "Error booking room", JOptionPane.ERROR_MESSAGE); } } } catch (RemoteException ex) { ex.printStackTrace(); } } //Call event handler, which in turn will make the client's data up to date // drpRoomListActionPerformed(null); setUpUserAccountInfo(); } // This method is used to update certain data based on a change on the server side public void setUpUserAccountInfo() { ArrayList userBookings; drpNewBookings.removeAllItems(); drpOldBookings.removeAllItems(); try { userBookings = healthSpa.getMemberBookingInfo(guiUsername, guiPassword, member.getCode()); lblAccountID.setText(member.getCode()); lblName.setText(member.getName()); drpNewBookings.removeAllItems(); drpOldBookings.removeAllItems(); for (Iterator i = userBookings.iterator(); i.hasNext();) { Booking tempBooking = i.next(); if (tempBooking.isPaid() == false) { drpNewBookings.addItem(tempBooking); } else drpOldBookings.addItem(tempBooking); } } catch (RemoteException ex) { ex.printStackTrace(); } } /* * Entry method */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new ClientUI().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton btnCancelBooking; private javax.swing.JButton btnChangePassword; private javax.swing.JButton btnDetails; private javax.swing.JButton btnViewBooking; private javax.swing.JComboBox drpMemberList; private javax.swing.JComboBox drpNewBookings; private javax.swing.JComboBox drpOldBookings; private javax.swing.JComboBox drpRoomList; private javax.swing.JComboBox drpRoomWeek; private javax.swing.JComboBox drpRooms; private javax.swing.JComboBox drpStaffList; private javax.swing.JComboBox drpStaffWeek; private javax.swing.JComboBox drpTimePeriod; private javax.swing.JComboBox drpUnpaidBookings; private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel10; private javax.swing.JLabel jLabel11; private javax.swing.JLabel jLabel12; private javax.swing.JLabel jLabel13; private javax.swing.JLabel jLabel14; private javax.swing.JLabel jLabel15; private javax.swing.JLabel jLabel16; private javax.swing.JLabel jLabel17; private javax.swing.JLabel jLabel18; private javax.swing.JLabel jLabel19; private javax.swing.JLabel jLabel2; private javax.swing.JLabel jLabel20; private javax.swing.JLabel jLabel21; private javax.swing.JLabel jLabel22; private javax.swing.JLabel jLabel23; private javax.swing.JLabel jLabel24; private javax.swing.JLabel jLabel25; private javax.swing.JLabel jLabel3; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel jLabel6; private javax.swing.JLabel jLabel7; private javax.swing.JLabel jLabel8; private javax.swing.JLabel jLabel9; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JPanel jPanel3; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane2; private javax.swing.JScrollPane jScrollPane3; private javax.swing.JScrollPane jScrollPane5; private javax.swing.JSeparator jSeparator1; private javax.swing.JTabbedPane jTabbedPane1; private javax.swing.JTable jTable1; private javax.swing.JLabel lblAccountID; private javax.swing.JLabel lblCurrentPrice; private javax.swing.JLabel lblName; private javax.swing.JLabel lblNote; private javax.swing.JButton loginButton; private javax.swing.JLabel loginStatus; private javax.swing.JButton logoutButton; private javax.swing.JPanel pnlAddUser; private javax.swing.JPanel pnlChangePassword; private javax.swing.JPanel pnlRecordPayment; private javax.swing.JPanel pnlSetPrice; private javax.swing.JPanel pnlViewAccount; private javax.swing.JTable tblRoomNames; private javax.swing.JTable tblRoomTimetable; private javax.swing.JTable tblStaffTimetable; private javax.swing.JTabbedPane tpUserPanel; private javax.swing.JPasswordField txtCurrentPassword; private javax.swing.JTextField txtCurrentUsername; private javax.swing.JPasswordField txtNewPassword; private javax.swing.JTextField txtNewPrice; private javax.swing.JTextField txtNewUserName; private javax.swing.JTextField txtNewUserPassword; private javax.swing.JTextField txtNewUserUsername; private javax.swing.JPasswordField txtPassword; private javax.swing.JTextField txtUsername; // End of variables declaration//GEN-END:variables }