├── .DS_Store ├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── encodings.xml ├── libraries │ ├── Maven__junit_junit_4_11.xml │ ├── Maven__mysql_mysql_connector_java_5_1_21.xml │ └── Maven__org_hamcrest_hamcrest_core_1_3.xml ├── misc.xml ├── modules.xml ├── uiDesigner.xml └── vcs.xml ├── Java-Calendar.iml ├── README.md ├── java_calendar.sql ├── pom.xml ├── src ├── .DS_Store ├── main │ ├── .DS_Store │ └── java │ │ ├── .DS_Store │ │ └── edu │ │ ├── .DS_Store │ │ └── avans │ │ ├── .DS_Store │ │ └── library │ │ ├── businesslogic │ │ └── CalendarManager.java │ │ ├── datastorage │ │ ├── AppointmentDAO.java │ │ ├── CategoryDAO.java │ │ └── DatabaseConnection.java │ │ ├── domain │ │ ├── Appointment.java │ │ ├── CCalendar.java │ │ ├── CDay.java │ │ ├── CMonth.java │ │ ├── CWeek.java │ │ ├── CYear.java │ │ └── Category.java │ │ ├── main │ │ └── Main.java │ │ └── presentation │ │ ├── AppointmentFrame.java │ │ ├── AppointmentPanel.java │ │ ├── CalendarPanel.java │ │ ├── DayDetailPanel.java │ │ ├── DayPanel.java │ │ ├── MainFrame.java │ │ ├── MainPanel.java │ │ ├── MonthPanel.java │ │ └── SpringUtilities.java └── test │ └── java │ ├── calendar │ └── CalendarTest.java │ ├── day │ └── DayTest.java │ ├── month │ └── MonthTest.java │ └── week │ └── WeekTest.java └── target ├── classes └── edu │ └── avans │ └── library │ ├── businesslogic │ └── CalendarManager.class │ ├── datastorage │ ├── AppointmentDAO.class │ ├── CategoryDAO.class │ └── DatabaseConnection.class │ ├── domain │ ├── Appointment.class │ ├── CCalendar.class │ ├── CDay.class │ ├── CMonth.class │ ├── CWeek.class │ ├── CYear.class │ └── Category.class │ ├── main │ └── Main.class │ └── presentation │ ├── AppointmentFrame.class │ ├── AppointmentPanel$saveAppointmentHandler.class │ ├── AppointmentPanel.class │ ├── CalendarPanel.class │ ├── DayDetailPanel$deleteAppointmentHandler.class │ ├── DayDetailPanel.class │ ├── DayPanel$addAppointmentsButtonHandler.class │ ├── DayPanel$viewAppointmentsButtonHandler.class │ ├── DayPanel.class │ ├── MainFrame$1.class │ ├── MainFrame.class │ ├── MainPanel$currentMonthButtonHandler.class │ ├── MainPanel$dateFieldHandler.class │ ├── MainPanel$nextMonthButtonHandler.class │ ├── MainPanel$prevMonthButtonHandler.class │ ├── MainPanel$resizeListener.class │ ├── MainPanel.class │ ├── MonthPanel.class │ └── SpringUtilities.class └── test-classes ├── appointment └── AppointmentTest.class ├── calendar └── CalendarTest.class ├── day └── DayTest.class └── week └── WeekTest.class /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bramdehart/java-calendar/fc4973e95ded13790010163849fc4319d2715fb9/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | .idea/workspace.xml 3 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/encodings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__junit_junit_4_11.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__mysql_mysql_connector_java_5_1_21.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 24 | 25 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/uiDesigner.xml: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Java-Calendar.iml: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Java Calendar made with the Swing GUI toolkit 2 | 3 | ## Installation 4 | An SQL-import is required before using the application. See attached SQL-file. 5 | 6 | ## Navigation 7 | Navigation between different monthpanels can be done in two ways: 8 | * Entering a date in the toppanel 9 | * Using the navigation buttons (previous / current / next month) 10 | 11 | ## Add an appointment 12 | An appointment can be added by clicking on "Add" within the desired daypanel. 13 | The fields "Name", "Start time" and "End time" are required. The others are optional. 14 | 15 | ## Delete / View an appointment 16 | To delete an appointment, click on "View" within the desired daypanel. The daydetail-panel on the right will show the appointments of the selected day. Confirm your removal by clicking on "Delete". 17 | 18 | ## Color descriptions 19 | * Yellow: 0 - 5 appointments 20 | * Orange: 5 - 10 appointments 21 | * Red: > 10 appointments 22 | * Green: current day 23 | * Blue: active day 24 | 25 | ## Screenshots 26 | ![](http://bramdehart.nl/screenshots/Screen%20Shot%202016-12-06%20at%2022.05.06.png) 27 | -------------------------------------------------------------------------------- /java_calendar.sql: -------------------------------------------------------------------------------- 1 | # ************************************************************ 2 | # Sequel Pro SQL dump 3 | # Version 4499 4 | # 5 | # http://www.sequelpro.com/ 6 | # https://github.com/sequelpro/sequelpro 7 | # 8 | # Host: 127.0.0.1 (MySQL 5.6.14) 9 | # Database: javaCalendar 10 | # Generation Time: 2017-01-26 19:18:28 +0000 11 | # ************************************************************ 12 | 13 | 14 | /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; 15 | /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; 16 | /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; 17 | /*!40101 SET NAMES utf8 */; 18 | /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; 19 | /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; 20 | /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; 21 | 22 | 23 | # Dump of table appointment 24 | # ------------------------------------------------------------ 25 | 26 | DROP TABLE IF EXISTS `appointment`; 27 | 28 | CREATE TABLE `appointment` ( 29 | `id` int(11) unsigned NOT NULL AUTO_INCREMENT, 30 | `title` varchar(255) NOT NULL DEFAULT '', 31 | `description` varchar(255) DEFAULT NULL, 32 | `location` varchar(255) DEFAULT NULL, 33 | `date` date NOT NULL, 34 | `startTime` time NOT NULL, 35 | `endTime` time NOT NULL, 36 | PRIMARY KEY (`id`) 37 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 38 | 39 | LOCK TABLES `appointment` WRITE; 40 | /*!40000 ALTER TABLE `appointment` DISABLE KEYS */; 41 | 42 | INSERT INTO `appointment` (`id`, `title`, `description`, `location`, `date`, `startTime`, `endTime`) 43 | VALUES 44 | (79,'Event 1',NULL,NULL,'2016-12-21','09:00:00','10:00:00'), 45 | (80,'Event 2',NULL,NULL,'2016-12-21','10:00:00','11:00:00'), 46 | (81,'Event 3',NULL,NULL,'2016-12-21','12:00:00','13:00:00'), 47 | (82,'Event 4',NULL,NULL,'2016-12-21','13:00:00','14:00:00'), 48 | (83,'Event 5',NULL,NULL,'2016-12-21','15:00:00','16:00:00'), 49 | (84,'Event 6',NULL,NULL,'2016-12-21','16:00:00','17:00:00'), 50 | (85,'Event 7',NULL,NULL,'2016-12-21','17:00:00','18:00:00'), 51 | (86,'Event 8',NULL,NULL,'2016-12-21','18:00:00','19:00:00'), 52 | (87,'Event 9',NULL,NULL,'2016-12-21','19:00:00','20:00:00'), 53 | (88,'Event 10',NULL,NULL,'2016-12-21','20:00:00','21:00:00'), 54 | (89,'Event 11',NULL,NULL,'2016-12-21','21:00:00','22:00:00'), 55 | (90,'Event 1',NULL,NULL,'2016-12-09','09:00:00','10:00:00'), 56 | (91,'Event 2',NULL,NULL,'2016-12-09','10:00:00','11:00:00'), 57 | (92,'Event 3',NULL,NULL,'2016-12-09','12:00:00','13:00:00'), 58 | (93,'Event 4',NULL,NULL,'2016-12-09','13:00:00','14:00:00'), 59 | (94,'Event 5',NULL,NULL,'2016-12-09','15:00:00','16:00:00'), 60 | (95,'Event 6',NULL,NULL,'2016-12-09','16:00:00','17:00:00'), 61 | (96,'Event 7',NULL,NULL,'2016-12-09','17:00:00','18:00:00'), 62 | (97,'Event 1',NULL,NULL,'2016-12-26','09:00:00','10:00:00'), 63 | (98,'Event 2',NULL,NULL,'2016-12-26','10:00:00','11:00:00'), 64 | (99,'Event 3',NULL,NULL,'2016-12-26','12:00:00','13:00:00'), 65 | (100,'Event 4',NULL,NULL,'2016-12-26','13:00:00','14:00:00'), 66 | (101,'Event 1',NULL,NULL,'2016-11-30','09:00:00','10:00:00'), 67 | (103,'Event 1',NULL,NULL,'2016-11-28','09:00:00','10:00:00'), 68 | (104,'Event 2',NULL,NULL,'2016-11-28','10:00:00','11:00:00'), 69 | (105,'Event 1',NULL,NULL,'2017-01-04','09:00:00','10:00:00'), 70 | (107,'Event 1',NULL,NULL,'2017-01-05','09:00:00','10:00:00'), 71 | (108,'Event 2',NULL,NULL,'2017-01-05','10:00:00','11:00:00'), 72 | (109,'Event 3',NULL,NULL,'2017-01-05','11:00:00','12:00:00'), 73 | (110,'Event 4',NULL,NULL,'2017-01-05','12:00:00','13:00:00'), 74 | (111,'Event 5',NULL,NULL,'2017-01-05','13:00:00','14:00:00'), 75 | (112,'Event 6',NULL,NULL,'2017-01-05','14:00:00','15:00:00'), 76 | (113,'Event 7',NULL,NULL,'2017-01-05','15:00:00','16:00:00'), 77 | (114,'Event 8',NULL,NULL,'2017-01-05','16:00:00','17:00:00'), 78 | (115,'New event',NULL,NULL,'2016-11-17','09:00:00','10:00:00'), 79 | (118,'jty','rty','ghj','2017-01-02','10:00:00','11:00:00'); 80 | 81 | /*!40000 ALTER TABLE `appointment` ENABLE KEYS */; 82 | UNLOCK TABLES; 83 | 84 | 85 | # Dump of table category 86 | # ------------------------------------------------------------ 87 | 88 | DROP TABLE IF EXISTS `category`; 89 | 90 | CREATE TABLE `category` ( 91 | `id` int(11) unsigned NOT NULL AUTO_INCREMENT, 92 | `title` varchar(255) NOT NULL DEFAULT '', 93 | `color` varchar(6) NOT NULL DEFAULT '', 94 | PRIMARY KEY (`id`) 95 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 96 | 97 | 98 | 99 | 100 | /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; 101 | /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; 102 | /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; 103 | /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; 104 | /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; 105 | /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; 106 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | edu.avans.library 6 | JavaCalendar 7 | JavaCalendar 8 | jar 9 | 1.0.0.RELEASE 10 | 11 | UTF-8 12 | 1.8 13 | 14 | 15 | 16 | 17 | junit 18 | junit 19 | 4.11 20 | test 21 | 22 | 23 | 24 | 25 | mysql 26 | mysql-connector-java 27 | 5.1.21 28 | 29 | 30 | 31 | 32 | 33 | JavaCalendar 34 | 35 | 36 | 37 | org.apache.maven.plugins 38 | maven-compiler-plugin 39 | 2.3.2 40 | 41 | ${java-version} 42 | ${java-version} 43 | -Xlint:all 44 | true 45 | true 46 | 47 | 48 | 49 | org.codehaus.mojo 50 | exec-maven-plugin 51 | 1.2.1 52 | 53 | org.test.int1.Main 54 | 55 | 56 | 57 | org.apache.maven.plugins 58 | maven-jar-plugin 59 | 2.4 60 | 61 | 62 | 63 | test-jar 64 | 65 | 66 | 67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /src/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bramdehart/java-calendar/fc4973e95ded13790010163849fc4319d2715fb9/src/.DS_Store -------------------------------------------------------------------------------- /src/main/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bramdehart/java-calendar/fc4973e95ded13790010163849fc4319d2715fb9/src/main/.DS_Store -------------------------------------------------------------------------------- /src/main/java/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bramdehart/java-calendar/fc4973e95ded13790010163849fc4319d2715fb9/src/main/java/.DS_Store -------------------------------------------------------------------------------- /src/main/java/edu/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bramdehart/java-calendar/fc4973e95ded13790010163849fc4319d2715fb9/src/main/java/edu/.DS_Store -------------------------------------------------------------------------------- /src/main/java/edu/avans/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bramdehart/java-calendar/fc4973e95ded13790010163849fc4319d2715fb9/src/main/java/edu/avans/.DS_Store -------------------------------------------------------------------------------- /src/main/java/edu/avans/library/businesslogic/CalendarManager.java: -------------------------------------------------------------------------------- 1 | package edu.avans.library.businesslogic; 2 | 3 | import edu.avans.library.datastorage.*; 4 | import edu.avans.library.domain.Appointment; 5 | import java.sql.Time; 6 | import java.util.ArrayList; 7 | import java.util.Date; 8 | 9 | /** 10 | * The CalendarManager manages communication between the different classes in the presentation, domain and data-storage level. 11 | * When CalendarManager is initialized, a database connection is ensured. 12 | * @author Bram de Hart 13 | * @version 1.0 14 | */ 15 | public class CalendarManager { 16 | private AppointmentDAO appointment = new AppointmentDAO(); 17 | 18 | /** 19 | * Gets all appointments of a given date. 20 | * @param date the date the appointments needs to be retrieved from 21 | * @return arraylist of appointments 22 | */ 23 | public ArrayList getAppointments(Date date) { 24 | return appointment.getAppointments(date); 25 | } 26 | 27 | /** 28 | * Inserts a new appointment in the database. 29 | * @param date the date the appointment needs to be added to 30 | * @param title the title of the appointment 31 | * @param location the location of the appointment 32 | * @param description a description of the appointment 33 | * @param startTime the starttime of the appointment 34 | * @param endTime the endtime of the appointment 35 | * @return boolean 36 | */ 37 | public boolean addAppointment(Date date, String title, String description, String location, Time startTime, Time endTime) { 38 | return appointment.addAppointment(date, title, description, location, startTime, endTime); 39 | } 40 | 41 | /** 42 | * Deletes an appointment from the database. 43 | * @param appointmentId the id of the appointment that needs to be removed 44 | * @return boolean 45 | */ 46 | public boolean deleteAppointment(Integer appointmentId) { 47 | return appointment.deleteAppointment(appointmentId); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/edu/avans/library/datastorage/AppointmentDAO.java: -------------------------------------------------------------------------------- 1 | package edu.avans.library.datastorage; 2 | 3 | import java.sql.ResultSet; 4 | import java.sql.SQLException; 5 | import java.text.SimpleDateFormat; 6 | import java.util.ArrayList; 7 | import java.util.Date; 8 | import java.sql.Time; 9 | import java.util.List; 10 | import edu.avans.library.domain.Appointment; 11 | 12 | /** 13 | * AppointmentDAO handles database requests that are related to Appointment. 14 | * It is called by the CalendarManager. 15 | * @author Bram de Hart 16 | * @version 1.0 17 | * @see edu.avans.library.domain.Appointment 18 | * @see edu.avans.library.businesslogic.CalendarManager 19 | */ 20 | public class AppointmentDAO { 21 | private DatabaseConnection connection = new DatabaseConnection("jdbc:mysql://127.0.0.1/java_calendar", "root","root"); 22 | 23 | /** 24 | * Gets all appointments of a given date. 25 | * @param date the date the appointments needs to be retrieved from 26 | */ 27 | public ArrayList getAppointments(Date date) { 28 | ArrayList appointments = new ArrayList(); 29 | String dateString = new SimpleDateFormat("yyyy-MM-dd").format(date); 30 | 31 | if(date != null) { 32 | // First open a database connnection 33 | if (connection.open()) { 34 | // If a connection was successfully setup, execute the SELECT statement. 35 | ResultSet resultset = connection.executeQuery( 36 | "SELECT * FROM appointment WHERE date = '" + dateString + "' ORDER BY startTime;"); 37 | 38 | if (resultset != null) { 39 | try { 40 | while (resultset.next()) { 41 | // get fields 42 | Integer appointmentId = resultset.getInt("id"); 43 | String title = resultset.getString("title"); 44 | String description = resultset.getString("description"); 45 | String location = resultset.getString("location"); 46 | Time startTime = resultset.getTime("startTime"); 47 | Time endTime = resultset.getTime("endTime"); 48 | 49 | // add appointment to list 50 | Appointment appointment = new Appointment(appointmentId, title, description, location, date, startTime, endTime); 51 | appointments.add(appointment); 52 | } 53 | } catch (SQLException e) { 54 | System.out.println(e); 55 | } 56 | } 57 | 58 | // We had a database connection opened. Since we're finished, 59 | // we need to close it. 60 | connection.close(); 61 | } 62 | } 63 | 64 | return appointments; 65 | } 66 | 67 | /** 68 | * Inserts a new appointment in the database. 69 | * @param date the date the appointment needs to be added to 70 | * @param title the title of the appointment 71 | * @param location the location of the appointment 72 | * @param description a description of the appointment 73 | * @param startTime the starttime of the appointment 74 | * @param endTime the endtime of the appointment 75 | */ 76 | public Boolean addAppointment(Date date, String title, String description, String location, Time startTime, Time endTime) { 77 | List resultIds = new ArrayList(); 78 | 79 | if (date != null && title != null && date != null && startTime != null && endTime != null) { 80 | // First open a database connnection 81 | if (connection.open()) { 82 | // If a connection was successfully setup, execute the statement. 83 | resultIds = connection.executePrepared("INSERT INTO appointment (title, description, location, date, startTime, endTime) VALUES(?,?,?,?,?,?);", 84 | title,description,location,date,startTime,endTime); 85 | } 86 | 87 | // We had a database connection opened. Since we're finished, 88 | // we need to close it. 89 | connection.close(); 90 | } 91 | return resultIds.isEmpty(); 92 | } 93 | 94 | /** 95 | * Deletes an appointment from the database. 96 | * @param appointmentId the id of the appointment. 97 | */ 98 | public boolean deleteAppointment(Integer appointmentId) { 99 | boolean result = false; 100 | if (appointmentId != null) { 101 | // First open a database connnection 102 | if (connection.open()) { 103 | // If a connection was successfully setup, execute the statement. 104 | result = connection.execute("DELETE FROM appointment WHERE id = '"+appointmentId+"';"); 105 | } 106 | 107 | // We had a database connection opened. Since we're finished, 108 | // we need to close it. 109 | connection.close(); 110 | } 111 | return result; 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /src/main/java/edu/avans/library/datastorage/CategoryDAO.java: -------------------------------------------------------------------------------- 1 | package edu.avans.library.datastorage; 2 | 3 | /** 4 | * CategoryDAO handles database requests that are related to Category. 5 | * It is called by the CalendarManager. 6 | * @author Bram de Hart 7 | * @version 1.0 8 | * @see edu.avans.library.domain.Category 9 | * @see edu.avans.library.businesslogic.CalendarManager 10 | */ 11 | public class CategoryDAO { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/edu/avans/library/datastorage/DatabaseConnection.java: -------------------------------------------------------------------------------- 1 | package edu.avans.library.datastorage; 2 | 3 | import java.sql.*; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | import java.util.logging.Level; 7 | import java.util.logging.Logger; 8 | 9 | /** 10 | * A wrapper class to make database actions easier to write. 11 | */ 12 | public class DatabaseConnection { 13 | private static final Logger LOGGER; 14 | 15 | static { 16 | LOGGER = Logger.getLogger(DatabaseConnection.class.getName()); 17 | } 18 | 19 | private final String connectionString; 20 | private final String user; 21 | private final String password; 22 | private Connection connection; 23 | 24 | /** 25 | * Initializes a new DatabaseConnection instance using the specified connection string. 26 | * 27 | * @param connectionString The connection string to create the connection with. 28 | * @param user The user to create the connection with. 29 | * @param password The password to create the connection with. 30 | */ 31 | public DatabaseConnection(String connectionString, String user, String password) { 32 | this.connectionString = connectionString; 33 | this.user = user; 34 | this.password = password; 35 | } 36 | 37 | /** 38 | * Opens the connection. 39 | * 40 | * @return true if successful; otherwise, false. 41 | */ 42 | public boolean open() { 43 | if (isOpen()) { 44 | return true; 45 | } 46 | 47 | try { 48 | connection = DriverManager.getConnection(connectionString, user, password); 49 | return true; 50 | } catch (Exception e) { 51 | LOGGER.log(Level.SEVERE, "An exception occurred while trying to open the database connection.", e); 52 | return false; 53 | } 54 | } 55 | 56 | /** 57 | * Checks if the connection is currently open. 58 | * @return true if open; otherwise, false. 59 | */ 60 | public boolean isOpen() { 61 | if (connection == null) { 62 | return false; 63 | } 64 | 65 | try { 66 | return !connection.isClosed(); 67 | } catch (Exception e) { 68 | LOGGER.log(Level.SEVERE, "An exception occurred while trying to check if the database connection is open.", e); 69 | return false; 70 | } 71 | } 72 | 73 | /** 74 | * Closes the connection. 75 | * @return true if successful; otherwise, false. 76 | */ 77 | public boolean close() { 78 | if (!isOpen()) { 79 | return true; 80 | } 81 | 82 | try { 83 | connection.close(); 84 | connection = null; 85 | return true; 86 | } catch (Exception e) { 87 | LOGGER.log(Level.SEVERE, "An exception occurred while trying to close the database connection.", e); 88 | return false; 89 | } 90 | } 91 | 92 | /** 93 | * Executes SQL that does not return any results. 94 | * @param sql The sql to be executed 95 | * @return true if successful; otherwise, false. 96 | */ 97 | public boolean execute(String sql) { 98 | try { 99 | Statement statement = connection.createStatement(); 100 | return statement.execute(sql); 101 | } catch (Exception e) { 102 | LOGGER.log(Level.SEVERE, "An exception occurred while trying to execute the statement.", e); 103 | return false; 104 | } 105 | } 106 | 107 | /** 108 | * Executes SQL that does not return any results. 109 | * @param sql The sql to be executed 110 | * @return true if successful; otherwise, false. 111 | */ 112 | public int[] executeBatch(String... sql) { 113 | try { 114 | Statement statement = connection.createStatement(); 115 | for (String sqlLine : sql) { 116 | statement.addBatch(sqlLine); 117 | } 118 | return statement.executeBatch(); 119 | } catch (Exception e) { 120 | LOGGER.log(Level.SEVERE, "An exception occurred while trying to execute the statement.", e); 121 | return new int[0]; 122 | } 123 | } 124 | 125 | /** 126 | * Executes an SQL query that returns results. 127 | * @param sql The sql to be executed 128 | * @return The result set returned by the query. 129 | */ 130 | public ResultSet executeQuery(String sql) { 131 | try { 132 | Statement statement = connection.createStatement(); 133 | return statement.executeQuery(sql); 134 | } catch (Exception e) { 135 | LOGGER.log(Level.SEVERE, "An exception occurred while trying to execute the query.", e); 136 | return null; 137 | } 138 | } 139 | 140 | /** 141 | * Creates and executes an SQL string by placing the specified items into the SQL format string and returns the generated keys. 142 | * @param sqlFormat The SQL string to place the items in. 143 | * @param items The items to place into the SQL format string. 144 | * @return The generated keys as an integer List. 145 | */ 146 | public List executePrepared(String sqlFormat, Object... items) { 147 | try { 148 | PreparedStatement statement = connection.prepareStatement(sqlFormat, Statement.RETURN_GENERATED_KEYS); 149 | 150 | int itemCount = items.length; 151 | 152 | for (int i = 0; i < itemCount; i++) { 153 | statement.setObject(i + 1, items[i]); 154 | } 155 | 156 | statement.execute(); 157 | 158 | List generatedIds = new ArrayList<>(); 159 | 160 | ResultSet generatedKeys = statement.getGeneratedKeys(); 161 | while (generatedKeys.next()) { 162 | generatedIds.add(generatedKeys.getInt(1)); 163 | } 164 | 165 | return generatedIds; 166 | } catch (Exception e) { 167 | LOGGER.log(Level.SEVERE, "An exception occurred while trying to execute the prepared statement.", e); 168 | return new ArrayList<>(); 169 | } 170 | } 171 | 172 | /** 173 | * Creates and executes an SQL string for each set of items in the specified batch by placing the specified items into the SQL format string and returns the number of affected rows. 174 | * @param sqlFormat The SQL string to place the items in. 175 | * @param batch The batch with item collections to place in the SQL string. 176 | * @return The number of affected rows as an integer List. 177 | */ 178 | public int[] executePreparedBatch(String sqlFormat, List batch) { 179 | try { 180 | PreparedStatement statement = connection.prepareStatement(sqlFormat); 181 | 182 | for (Object[] items : batch) { 183 | int itemCount = items.length; 184 | 185 | for (int i = 0; i < itemCount; i++) { 186 | statement.setObject(i + 1, items[i]); 187 | } 188 | 189 | statement.addBatch(); 190 | } 191 | 192 | return statement.executeBatch(); 193 | } catch (Exception e) { 194 | LOGGER.log(Level.SEVERE, "An exception occurred while trying to execute the prepared statement batch.", e); 195 | return new int[0]; 196 | } 197 | } 198 | } -------------------------------------------------------------------------------- /src/main/java/edu/avans/library/domain/Appointment.java: -------------------------------------------------------------------------------- 1 | package edu.avans.library.domain; 2 | 3 | import java.util.Date; 4 | import java.sql.Time; 5 | 6 | /** 7 | * The class Appointent represents an appointment. 8 | * They are served via the CalendarManager. 9 | * @author Bram de Hart 10 | * @version 1.0 11 | * @see Category 12 | * @see edu.avans.library.businesslogic.CalendarManager 13 | */ 14 | 15 | public class Appointment { 16 | public Integer appointmentId; 17 | public String title, description, location; 18 | private Date date; 19 | public Time startTime, endTime; 20 | 21 | /** 22 | * Constructor. Sets the given variables/ 23 | */ 24 | public Appointment(Integer appointmentId, String title, String description, String location, Date date, Time startTime, Time endTime) { 25 | this.appointmentId = appointmentId; 26 | this.title = title; 27 | this.description = description; 28 | this.location = location; 29 | this.date = date; 30 | this.startTime = startTime; 31 | this.endTime = endTime; 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/edu/avans/library/domain/CCalendar.java: -------------------------------------------------------------------------------- 1 | package edu.avans.library.domain; 2 | 3 | import java.text.ParseException; 4 | import java.text.SimpleDateFormat; 5 | import java.util.Date; 6 | 7 | /** 8 | * CCalendar represents the logical side of the calendar application. 9 | * It is mainly called by the CalendarManager. 10 | * @author Bram de Hart 11 | * @version 1.0 12 | * @see edu.avans.library.businesslogic.CalendarManager 13 | */ 14 | public class CCalendar { 15 | public CYear year; 16 | public CMonth month; 17 | public CWeek week; 18 | public CDay day; 19 | 20 | /** 21 | * Constructor of the CCalendar object. 22 | */ 23 | public CCalendar() { 24 | initCalendar(); 25 | } 26 | 27 | /** 28 | * Inits a new calendar 29 | */ 30 | void initCalendar() { 31 | year = new CYear(); 32 | month = new CMonth(); 33 | week = new CWeek(); 34 | day = new CDay(); 35 | } 36 | 37 | /** 38 | * Updates the active date by moving one month earlier. 39 | */ 40 | public void toPrevMonth() { 41 | if (month.getActiveMonth() == 0) { 42 | // active month is januari, set new one to december 43 | month.setActiveMonth(11); 44 | // set new year 45 | year.setActiveYear(year.getPreviousYear()); 46 | } 47 | else { 48 | // set previous month to active month 49 | month.setActiveMonth(month.getPreviousMonth()); 50 | } 51 | 52 | day.setActiveDay(1, month.getDayCount(month.getActiveMonth(), year.getActiveYear())); 53 | week.setActiveWeek(week.getWeekNumber(getDate(month.getActiveMonth(), day.getActiveDay(), year.getActiveYear()))); 54 | 55 | day.setPreviousDay(); 56 | day.setNextDay(); 57 | week.setPreviousWeek(); 58 | week.setNextWeek(); 59 | month.setPreviousMonth(); 60 | month.setNextMonth(); 61 | year.setPreviousYear(); 62 | year.setNextYear(); 63 | } 64 | 65 | /** 66 | * Updates the active date by moving to the current month. 67 | */ 68 | public void toCurrentMonth() { 69 | day.setActiveDay(1, month.getDayCount(month.getActiveMonth(), year.getActiveYear())); 70 | day.setPreviousDay(); 71 | day.setNextDay(); 72 | week.setActiveWeek(week.getCurrentWeek()); 73 | week.setPreviousWeek(); 74 | week.setNextWeek(); 75 | month.setActiveMonth(month.getCurrentMonth()); 76 | month.setPreviousMonth(); 77 | month.setNextMonth(); 78 | year.setActiveYear(year.getCurrentYear()); 79 | year.setPreviousYear(); 80 | year.setNextYear(); 81 | } 82 | 83 | /** 84 | * Updates the active date by moving one month later. 85 | */ 86 | public void toNextMonth() { 87 | if (month.getActiveMonth() == 11) { 88 | // active month is december, set new one to januari 89 | month.setActiveMonth(0); 90 | // set new year 91 | year.setActiveYear(year.getNextYear()); 92 | } 93 | else { 94 | // set next month to active month 95 | month.setActiveMonth(month.getNextMonth()); 96 | } 97 | 98 | day.setActiveDay(1, month.getDayCount(month.getActiveMonth(), year.getActiveYear())); 99 | week.setActiveWeek(week.getWeekNumber(getDate(month.getActiveMonth(), day.getActiveDay(), year.getActiveYear()))); 100 | 101 | day.setPreviousDay(); 102 | day.setNextDay(); 103 | week.setPreviousWeek(); 104 | week.setNextWeek(); 105 | month.setPreviousMonth(); 106 | month.setNextMonth(); 107 | year.setPreviousYear(); 108 | year.setNextYear(); 109 | } 110 | 111 | /** 112 | * Updates the active date by overriding month, day, year and week. 113 | */ 114 | public void toDate(Integer month, Integer day, Integer year) { 115 | if (month > 12) { 116 | month = 1; 117 | } 118 | 119 | this.year.setActiveYear(year); 120 | this.month.setActiveMonth(month-1); // zero based 121 | this.day.setActiveDay(day, this.month.getDayCount(month-1, year)); 122 | this.week.setActiveWeek(this.week.getWeekNumber(getDate(month, day, year))); 123 | this.day.setPreviousDay(); 124 | this.day.setNextDay(); 125 | this.month.setPreviousMonth(); 126 | this.month.setNextMonth(); 127 | this.year.setPreviousYear(); 128 | this.year.setNextYear(); 129 | this.week.setPreviousWeek(); 130 | this.week.setNextWeek(); 131 | } 132 | 133 | /** 134 | * Returns the weeknumber based on a given date. 135 | * @param month the month of the given date 136 | * @param day the day of the given date 137 | * @param year the year of the given date 138 | * @return 139 | */ 140 | public Date getDate(Integer month, Integer day, Integer year) { 141 | SimpleDateFormat formatter = new SimpleDateFormat("M/d/yyyy"); 142 | String dateString = (month+1)+"/"+day+"/"+year; 143 | Date date = new Date(); 144 | 145 | try { 146 | date = formatter.parse(dateString); 147 | 148 | } catch (ParseException e) { 149 | e.printStackTrace(); 150 | } 151 | 152 | return date; 153 | } 154 | } -------------------------------------------------------------------------------- /src/main/java/edu/avans/library/domain/CDay.java: -------------------------------------------------------------------------------- 1 | package edu.avans.library.domain; 2 | 3 | import java.util.Calendar; 4 | 5 | /** 6 | * CDay contains methods and variables that are day-related. 7 | * It is mainly called by CCalendar and the CalendarManager. 8 | * @author Bram de Hart 9 | * @version 1.0 10 | * @see CCalendar 11 | * @see edu.avans.library.businesslogic.CalendarManager 12 | */ 13 | public class CDay { 14 | private Integer activeDay, prevDay, nextDay, currentDay; 15 | 16 | /** 17 | * Constructor. Sets the global day-variables. 18 | */ 19 | public CDay() { 20 | setDays(); 21 | } 22 | 23 | /** 24 | * Sets the global day-variables. 25 | */ 26 | private void setDays() { 27 | setCurrentDay(); 28 | setActiveDay(getCurrentDay(), null); 29 | setPreviousDay(); 30 | setNextDay(); 31 | } 32 | 33 | /** 34 | * Gets the previous day. 35 | * @return the previous day 36 | */ 37 | public Integer getPreviousDay() { 38 | return prevDay; 39 | } 40 | 41 | /** 42 | * Gets the next day. 43 | * @return the next day 44 | */ 45 | public Integer getNextDay() { 46 | return nextDay; 47 | } 48 | 49 | /** 50 | * Gets the current day. 51 | * @return the current day 52 | */ 53 | public Integer getCurrentDay() { 54 | return currentDay; 55 | } 56 | 57 | /** 58 | * Gets the active day. 59 | * @return the active day 60 | */ 61 | public Integer getActiveDay() { 62 | return activeDay; 63 | } 64 | 65 | /** 66 | * Sets the active day. 67 | * @param day the day that needs to be active 68 | * @param monthDays the total days of the month 69 | */ 70 | public void setActiveDay(Integer day, Integer monthDays) { 71 | activeDay = day; 72 | if (monthDays != null) { 73 | if (activeDay > monthDays) { 74 | activeDay = monthDays; 75 | } 76 | } 77 | if (activeDay < 1) { 78 | activeDay = 1; 79 | } 80 | } 81 | 82 | /** 83 | * Sets the previous day, based on the active day. 84 | */ 85 | public void setPreviousDay() { 86 | prevDay = activeDay-1; 87 | } 88 | 89 | /** 90 | * Sets the next daym based on the active day. 91 | */ 92 | public void setNextDay() { 93 | nextDay = activeDay+1; 94 | } 95 | 96 | /** 97 | * Sets the current day. 98 | */ 99 | public void setCurrentDay() { 100 | currentDay = Calendar.getInstance().get(Calendar.DAY_OF_MONTH); 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /src/main/java/edu/avans/library/domain/CMonth.java: -------------------------------------------------------------------------------- 1 | package edu.avans.library.domain; 2 | 3 | import java.text.DateFormatSymbols; 4 | import java.util.Calendar; 5 | 6 | /** 7 | * CMonth contains methods and variables that are month-related. 8 | * It is mainly called by CCalendar and the CalendarManager. 9 | * @author Bram de Hart 10 | * @version 1.0 11 | * @see CCalendar 12 | * @see edu.avans.library.businesslogic.CalendarManager 13 | */ 14 | public class CMonth { 15 | private Integer activeMonth, prevMonth, nextMonth, currentMonth; // for now private 16 | 17 | /** 18 | * Contstructor. Sets the global month-variables. 19 | */ 20 | public CMonth() { 21 | setMonths(); 22 | } 23 | 24 | /** 25 | * Sets the global month-variables. 26 | */ 27 | private void setMonths() { 28 | setCurrentMonth(); 29 | setActiveMonth(currentMonth); 30 | setPreviousMonth(); 31 | setNextMonth(); 32 | } 33 | 34 | /** 35 | * Gets the previous month. 36 | * @return the previous month 37 | */ 38 | public Integer getPreviousMonth() { 39 | return prevMonth; 40 | } 41 | 42 | /** 43 | * Gets the next month. 44 | * @return the next month 45 | */ 46 | public Integer getNextMonth() { 47 | return nextMonth; 48 | } 49 | 50 | /** 51 | * Gets the current month. 52 | * @return the current month 53 | */ 54 | public Integer getCurrentMonth() { 55 | return currentMonth; 56 | } 57 | 58 | /** 59 | * Gets the active month. 60 | * @return the active month 61 | */ 62 | public Integer getActiveMonth() { 63 | return activeMonth; 64 | } 65 | 66 | /** 67 | * Sets the previous month, based on the current month. 68 | */ 69 | public void setPreviousMonth() { 70 | if (activeMonth > 0) { 71 | prevMonth = activeMonth-1; 72 | } 73 | else { 74 | prevMonth = 11; 75 | } 76 | } 77 | 78 | /** 79 | * Sets the next month, based on the active month. 80 | */ 81 | public void setNextMonth() { 82 | if (activeMonth < 11) { 83 | nextMonth = activeMonth+1; 84 | } 85 | else { 86 | nextMonth = 0; 87 | } 88 | 89 | } 90 | 91 | /** 92 | * Sets the current month. 93 | */ 94 | public void setCurrentMonth() { 95 | currentMonth = Calendar.getInstance().get(Calendar.MONTH); 96 | } 97 | 98 | /** 99 | * Sets the active month. 100 | * @param month the month that needs to be active 101 | */ 102 | public void setActiveMonth(Integer month) { 103 | if (month > 11) { 104 | activeMonth = 11; 105 | } 106 | else if (month < 0) { 107 | activeMonth = 0; 108 | } 109 | else { 110 | activeMonth = month; 111 | } 112 | } 113 | 114 | /** 115 | * Gets to month name. 116 | * @param month the month as an integer (zero-based) 117 | * @return the month name as a string 118 | */ 119 | public String getMonthName(Integer month) { 120 | return new DateFormatSymbols().getMonths()[month]; 121 | } 122 | 123 | /** 124 | * Gets the sum of days in a given month. 125 | * @param month the month 126 | * @param year the year the month is in 127 | * @return 128 | */ 129 | public Integer getDayCount(Integer month, Integer year) { 130 | Calendar calendar = Calendar.getInstance(); 131 | calendar.set(Calendar.DATE, 1); 132 | calendar.set(Calendar.MONTH, month); 133 | calendar.set(Calendar.YEAR, year); 134 | return calendar.getActualMaximum(Calendar.DAY_OF_MONTH); 135 | } 136 | 137 | /** 138 | * Gets the first weekday of the month. 139 | * @param month the month 140 | * @param year the year the month is in 141 | * @return the first weekday of the month, zero based 142 | */ 143 | public Integer getFirstWeekDay(Integer month, Integer year) { 144 | Calendar calendar = Calendar.getInstance(); 145 | calendar.set(Calendar.DATE, 1); 146 | calendar.set(Calendar.MONTH, month); 147 | calendar.set(Calendar.YEAR, year); 148 | return calendar.get(Calendar.DAY_OF_WEEK); 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /src/main/java/edu/avans/library/domain/CWeek.java: -------------------------------------------------------------------------------- 1 | package edu.avans.library.domain; 2 | 3 | import java.util.Calendar; 4 | import java.text.SimpleDateFormat; 5 | import java.util.Date; 6 | 7 | /** 8 | * CWeek contains methods and variables that are week-related. 9 | * It is mainly called by CCalendar and the CalendarManager. 10 | * @author Bram de Hart 11 | * @version 1.0 12 | * @see CCalendar 13 | * @see edu.avans.library.businesslogic.CalendarManager 14 | */ 15 | public class CWeek { 16 | private Integer activeWeek, prevWeek, nextWeek, currentWeek; // for now private 17 | private Calendar cal = Calendar.getInstance(); 18 | 19 | /** 20 | * Contstructor. Sets the global month-variables. 21 | */ 22 | public CWeek() { 23 | setWeeks(); 24 | } 25 | 26 | /** 27 | * Sets the global week-variables. 28 | */ 29 | private void setWeeks() { 30 | setCurrentWeek(); 31 | setActiveWeek(currentWeek); 32 | setPreviousWeek(); 33 | setNextWeek(); 34 | } 35 | 36 | /** 37 | * Gets the previous week. 38 | * @return the previous week 39 | */ 40 | public Integer getPreviousWeek() { 41 | return prevWeek; 42 | } 43 | 44 | /** 45 | * Gets the next week. 46 | * @return the next week 47 | */ 48 | public Integer getNextWeek() { 49 | return nextWeek; 50 | } 51 | 52 | /** 53 | * Gets the current week. 54 | * @return the current week 55 | */ 56 | public Integer getCurrentWeek() { 57 | return currentWeek; 58 | } 59 | 60 | /** 61 | * Gets the active week. 62 | * @return the active week 63 | */ 64 | public Integer getActiveWeek() { 65 | return activeWeek; 66 | } 67 | 68 | /** 69 | * Sets the previous week, based on the current week. 70 | */ 71 | public void setPreviousWeek() { 72 | prevWeek = activeWeek-1; 73 | } 74 | 75 | /** 76 | * Sets the next week, based on the active week. 77 | */ 78 | public void setNextWeek() { 79 | nextWeek = activeWeek+1; 80 | } 81 | 82 | /** 83 | * Sets the current week. 84 | */ 85 | public void setCurrentWeek() { 86 | currentWeek = Calendar.getInstance().get(Calendar.WEEK_OF_YEAR); 87 | } 88 | 89 | /** 90 | * Sets the active week. 91 | * @param week the week that needs to be active 92 | */ 93 | public void setActiveWeek(Integer week) { 94 | activeWeek = week; 95 | } 96 | 97 | /** 98 | * Returns the weeknumber based on a given date. 99 | * @param date the date from which its week number needs to be requested 100 | * @return the weeknumber of the given date 101 | */ 102 | public Integer getWeekNumber(Date date) { 103 | cal.setTime(date); 104 | int week = cal.get(Calendar.WEEK_OF_YEAR); 105 | 106 | return week; 107 | } 108 | 109 | /** 110 | * Gets the weekday name. 111 | * @param date the date the weekday needs to be retrieved 112 | * @return the weekday as a string 113 | */ 114 | public String getWeekDayName(Date date) { 115 | return new SimpleDateFormat("EEEE").format(date); 116 | } 117 | 118 | 119 | } 120 | -------------------------------------------------------------------------------- /src/main/java/edu/avans/library/domain/CYear.java: -------------------------------------------------------------------------------- 1 | package edu.avans.library.domain; 2 | 3 | import java.util.Calendar; 4 | 5 | /** 6 | * CYear contains methods and variables that are year-related. 7 | * It is mainly called by CCalendar and the CalendarManager. 8 | * @author Bram de Hart 9 | * @version 1.0 10 | * @see CCalendar 11 | * @see edu.avans.library.businesslogic.CalendarManager 12 | */ 13 | public class CYear { 14 | private Integer activeYear, prevYear, nextYear, currentYear; // for now private 15 | 16 | /** 17 | * Constructor. Sets the global year-variables. 18 | */ 19 | public CYear() { 20 | setYears(); 21 | } 22 | 23 | /** 24 | * Sets the global year-variables. 25 | */ 26 | private void setYears() { 27 | setCurrentYear(); 28 | setActiveYear(getCurrentYear()); 29 | setPreviousYear(); 30 | setNextYear(); 31 | } 32 | 33 | /** 34 | * Gets the previous year, based on the active year. 35 | * @return the previous year 36 | */ 37 | public Integer getPreviousYear() { 38 | return prevYear; 39 | } 40 | 41 | /** 42 | * Gets the next year, based on the active year. 43 | * @return the next year 44 | */ 45 | public Integer getNextYear() { 46 | return nextYear; 47 | } 48 | 49 | /** 50 | * Gets the current year. 51 | * @return the current year 52 | */ 53 | public Integer getCurrentYear() { 54 | return currentYear; 55 | } 56 | 57 | /** 58 | * Gets the active year. 59 | * @return the active year 60 | */ 61 | public Integer getActiveYear() { 62 | return activeYear; 63 | } 64 | 65 | /** 66 | * Sets the active year. 67 | * @param year the year that needs to be active 68 | */ 69 | public void setActiveYear(Integer year) { 70 | activeYear = year; 71 | } 72 | 73 | /** 74 | * Sets the previous year, based on the active year. 75 | */ 76 | public void setPreviousYear() { 77 | prevYear = activeYear-1; 78 | } 79 | 80 | /** 81 | * Sets the next year, based on the active year. 82 | */ 83 | public void setNextYear() { 84 | nextYear = activeYear+1; 85 | } 86 | 87 | /** 88 | * Sets the current year. 89 | */ 90 | public void setCurrentYear() { 91 | currentYear = Calendar.getInstance().get(Calendar.YEAR); 92 | } 93 | 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/edu/avans/library/domain/Category.java: -------------------------------------------------------------------------------- 1 | package edu.avans.library.domain; 2 | 3 | import java.awt.*; 4 | 5 | /** 6 | * The class Category represents a category on which appointments can be attached. 7 | * They are served via the CalendarManager. 8 | * @author Bram de Hart 9 | * @version 1.0 10 | * @see Appointment 11 | * @see edu.avans.library.businesslogic.CalendarManager 12 | */ 13 | public class Category { 14 | private String title; 15 | private Color color; 16 | 17 | public Category() { 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/edu/avans/library/main/Main.java: -------------------------------------------------------------------------------- 1 | package edu.avans.library.main; 2 | 3 | import edu.avans.library.presentation.MainFrame; 4 | 5 | /** 6 | * The class Main is the main startup class of the calendar application. 7 | * @author Bram de Hart 8 | * @version 1.0 9 | */ 10 | public class Main { 11 | /** 12 | * Defaults constructor. Inits the main frame 13 | * @param args 14 | */ 15 | public static void main(String[] args) { 16 | MainFrame mainFrame = new MainFrame(); 17 | } 18 | } -------------------------------------------------------------------------------- /src/main/java/edu/avans/library/presentation/AppointmentFrame.java: -------------------------------------------------------------------------------- 1 | package edu.avans.library.presentation; 2 | 3 | import javax.swing.*; 4 | 5 | /** 6 | * The AppointmentFrame ensures the window of the popup used to add an appointment. 7 | * It is called by DayPanel. 8 | * @author Bram de Hart 9 | * @version 1.0 10 | * @see DayPanel 11 | */ 12 | public class AppointmentFrame extends JFrame { 13 | public Integer frameWidth = 292, frameHeight = 352; 14 | private AppointmentPanel appointmentPanel; // for now private 15 | private CalendarPanel calendarPanel; 16 | private Integer month, day, year; 17 | 18 | /** 19 | * Constructor. Calls the initialization of the frame. 20 | */ 21 | public AppointmentFrame(Integer month, Integer day, Integer year, CalendarPanel calendarPanel, Integer offsetX, Integer offsetY) { 22 | this.month = month; 23 | this.day = day; 24 | this.year = year; 25 | this.calendarPanel = calendarPanel; 26 | initFrame(offsetX, offsetY); 27 | } 28 | 29 | /** 30 | * Inits the frame. 31 | */ 32 | private void initFrame(Integer offsetX, Integer offsetY){ 33 | new JFrame(); 34 | setTitle("Add Event - "+String.format("%02d",(month+1))+"/"+String.format("%02d",day)+"/"+year); 35 | setResizable(false); 36 | setSize(frameWidth,frameHeight); 37 | setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 38 | setLocation(offsetX, offsetY); 39 | //setAlwaysOnTop(true); 40 | 41 | // add content to frame 42 | appointmentPanel = new AppointmentPanel(month, day, year, calendarPanel, this); 43 | setContentPane(appointmentPanel); 44 | pack(); 45 | setVisible(true); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/edu/avans/library/presentation/AppointmentPanel.java: -------------------------------------------------------------------------------- 1 | package edu.avans.library.presentation; 2 | 3 | import javax.swing.*; 4 | import java.awt.*; 5 | import java.awt.event.ActionEvent; 6 | import java.awt.event.ActionListener; 7 | import java.text.ParseException; 8 | import java.util.ArrayList; 9 | import java.util.Date; 10 | import java.sql.Time; 11 | import java.text.DateFormat; 12 | import java.text.SimpleDateFormat; 13 | import edu.avans.library.businesslogic.CalendarManager; 14 | 15 | /** 16 | * The AppointmentPanel ensures the panel of the AppointmentFrame. 17 | * Its shows the option to add an appointment and is placed within AppointmentFrame. 18 | * @author Bram de Hart 19 | * @version 1.0 20 | * @see AppointmentFrame 21 | * @see edu.avans.library.domain.Appointment 22 | */ 23 | public class AppointmentPanel extends JPanel { 24 | private Date date; 25 | private JFrame appointmentFrame; 26 | private CalendarPanel calendarPanel; 27 | private JTextField nameTextField, locationTextField, startTimeTextField, endTimeTextField, notesTextField; 28 | private Time formattedStartTime, formattedEndTime; 29 | private CalendarManager manager = new CalendarManager(); 30 | 31 | /** 32 | * Constructor. Sets the global variables and calls the draw method. 33 | * @param month the month of the clicked daypanel 34 | * @param day the day of the clicked daypanel 35 | * @param year the year of the clicked daypanel 36 | * @param calendarPanel the calendarpanel the clicked daypabel is part of, to have access to its (parents) methods 37 | */ 38 | public AppointmentPanel(Integer month, Integer day, Integer year, CalendarPanel calendarPanel, JFrame appointmentFrame) { 39 | this.calendarPanel = calendarPanel; 40 | this.appointmentFrame = appointmentFrame; 41 | this.date = calendarPanel.mainPanel.mainFrame.calendar.getDate(month, day, year); 42 | 43 | drawAppointmentPanel(); 44 | } 45 | 46 | /** 47 | * Draws the appointment panel. 48 | */ 49 | public void drawAppointmentPanel() { 50 | setLayout(new SpringLayout()); 51 | String[] labels = {"Name", "Location", "Start time", "End time", "Notes", ""}; 52 | int numPairs = labels.length; 53 | 54 | JButton saveButton = new JButton("Save"); 55 | saveButton.setPreferredSize(new Dimension(200,40)); 56 | saveButton.addActionListener(new saveAppointmentHandler()); 57 | 58 | ArrayList textFieldList = listTextFields(); 59 | 60 | // fill the panel 61 | for (int i = 0; i < numPairs; i++) { 62 | JLabel l = new JLabel(labels[i], JLabel.TRAILING); 63 | add(l); 64 | if (i+1 < numPairs) { 65 | add(textFieldList.get(i)); 66 | } 67 | else { 68 | add(saveButton); 69 | } 70 | } 71 | 72 | // lay out the panel 73 | SpringUtilities.makeCompactGrid(this, 74 | numPairs, 2, //rows, cols 75 | 10, 10, //initX, initY 76 | 10, 10 //xPad, yPad 77 | ); 78 | } 79 | 80 | /** 81 | * List the textfields for use with the for-loop in drawAppointments. 82 | * @return ArrayList of textfields 83 | */ 84 | private ArrayList listTextFields() { 85 | ArrayList textFieldList = new ArrayList<>(); 86 | textFieldList.add(nameTextField = new JTextField()); 87 | textFieldList.add(locationTextField = new JTextField()); 88 | textFieldList.add(startTimeTextField = new JTextField()); 89 | textFieldList.add(endTimeTextField = new JTextField()); 90 | textFieldList.add(notesTextField = new JTextField()); 91 | 92 | return textFieldList; 93 | } 94 | 95 | /** 96 | * Shows an message dialog when the name of an event isn't filled in. 97 | */ 98 | private void showNameError() { 99 | JOptionPane.showMessageDialog(null, "The name of the event must be filled in.", "Invalid name", JOptionPane.ERROR_MESSAGE); 100 | } 101 | 102 | /** 103 | * Show an message dialog when the filled in times aren't valid. 104 | */ 105 | private void showTimeError() { 106 | JOptionPane.showMessageDialog(null, 107 | "The start time or end time are invalid.\n" + 108 | "Allowed format: (00 through 23) : (00 through 59).\n" + 109 | "End time must be greater than start time.", "Invalid times", 110 | JOptionPane.ERROR_MESSAGE); 111 | } 112 | 113 | /** 114 | * Shows an message dialog when an event is succesfully added. 115 | * @param name the name of the event. 116 | */ 117 | private void showSuccesMessage(String name) { 118 | JOptionPane.showMessageDialog(null, "Your event \""+name+"\" is succesfully added.", "Event added", JOptionPane.PLAIN_MESSAGE); 119 | } 120 | 121 | /** 122 | * Sets the global formatted time variables, based on a time string 123 | * @param time 4 digit time as a string 124 | * @param timeType 0 or 1; startTime or endTime 125 | * @return true or false; validated and setted or not 126 | */ 127 | private Boolean setFormattedTime(String time, Integer timeType) { 128 | Boolean validated = true; 129 | Time formattedTime = new Time(new Date().getTime()); 130 | 131 | // format time 132 | DateFormat formatter = new SimpleDateFormat("HH:mm"); 133 | 134 | try { 135 | new SimpleDateFormat("HH:mm").parse(time); 136 | // good format 137 | formattedTime = new Time(formatter.parse(time).getTime()); 138 | } catch (ParseException e) { 139 | // bad format 140 | validated = false; 141 | } finally { 142 | if (validated) { 143 | if (timeType == 0) { 144 | // start time 145 | formattedStartTime = formattedTime; 146 | } 147 | else if (timeType == 1){ 148 | // end time 149 | formattedEndTime = formattedTime; 150 | } 151 | } 152 | } 153 | 154 | return validated; 155 | } 156 | 157 | /** 158 | * Inner class. Triggers an actionlistener when the addAppointmentButton is clicked. 159 | */ 160 | class saveAppointmentHandler implements ActionListener { 161 | /** 162 | * Opens new frame where a new appointment can be added. 163 | * @param e 164 | */ 165 | public void actionPerformed(ActionEvent e) { 166 | Boolean validName = true; 167 | Boolean validTimes = true; 168 | 169 | // get values 170 | String name = nameTextField.getText(); 171 | String notes = notesTextField.getText(); 172 | String location = locationTextField.getText(); 173 | String startTime = startTimeTextField.getText().replaceAll("\\s+",""); // remove whitespace 174 | String endTime = endTimeTextField.getText().replaceAll("\\s+",""); // remove whitespace 175 | 176 | // fields to null of not filled in 177 | if (notes.isEmpty()) { notes = null; } 178 | if (location.isEmpty()) { location = null; } 179 | 180 | // validate name 181 | if (name == null || name.isEmpty()) { 182 | validName = false; 183 | } 184 | // validate times 185 | if (!setFormattedTime(startTime, 0) || !setFormattedTime(endTime, 1)) { 186 | validTimes = false; 187 | } 188 | if (validTimes) { 189 | // is end time greater then start time 190 | if (Integer.parseInt(startTime.replaceAll("[^\\d]","")) > Integer.parseInt(endTime.replaceAll("[^\\d]",""))) { 191 | validTimes = false; 192 | } 193 | } 194 | 195 | if (validName && validTimes) { 196 | // add appointment 197 | manager.addAppointment(date, name, notes, location, formattedStartTime, formattedEndTime); 198 | // close frame 199 | appointmentFrame.setVisible(false); 200 | appointmentFrame.dispose(); 201 | // repaint panels and show succes message 202 | calendarPanel.monthPanel.redrawMonthPanel(); 203 | showSuccesMessage(name); 204 | } 205 | else { 206 | // show errors 207 | if(!validName) { showNameError(); } 208 | if(!validTimes) { showTimeError(); } 209 | } 210 | } 211 | } 212 | } 213 | -------------------------------------------------------------------------------- /src/main/java/edu/avans/library/presentation/CalendarPanel.java: -------------------------------------------------------------------------------- 1 | package edu.avans.library.presentation; 2 | import edu.avans.library.domain.CCalendar; 3 | import javax.swing.*; 4 | 5 | /** 6 | * The CalendarPanel ensures the panel in which the calendar user-interface will be placed. 7 | * It is placed within MainPanel. 8 | * @author Bram de Hart 9 | * @version 1.0 10 | * @see MainPanel 11 | */ 12 | public class CalendarPanel extends JPanel { 13 | private Integer calendarPanelWidth, calendarPanelHeight; 14 | private MainFrame mainFrame; // for now private 15 | public MainPanel mainPanel; 16 | public MonthPanel monthPanel; 17 | public CCalendar calendar; 18 | 19 | /** 20 | * Constructor. Creates an calendar object and inits the calendar-panel. 21 | * @param mainPanel is passed to have access to it's methods. 22 | */ 23 | public CalendarPanel(MainPanel mainPanel) { 24 | mainFrame = mainPanel.mainFrame; 25 | this.mainPanel = mainPanel; 26 | setCalendarPanelDimensions(); 27 | initCalendarPanel(); 28 | } 29 | 30 | /** 31 | * Inits the calendar-panel. 32 | */ 33 | private void initCalendarPanel() { 34 | setLayout(null); 35 | setCalendarPanelBounds(); 36 | drawMonthPanel(); 37 | } 38 | 39 | /** 40 | * Resizes the panels. Is called by an resizeListener inside MainPanel. 41 | */ 42 | public void resizeCalendarPanel() { 43 | setCalendarPanelDimensions(); 44 | setCalendarPanelBounds(); 45 | monthPanel.resizeMonthPanel(); 46 | } 47 | 48 | /** 49 | * Sets the calendar-panel's dimensions. 50 | */ 51 | private void setCalendarPanelDimensions() { 52 | calendarPanelWidth = mainFrame.getMainFrameWidth(); 53 | calendarPanelHeight = mainFrame.getMainFrameHeight() - mainPanel.getTopPanelHeight(); 54 | } 55 | 56 | /** 57 | * Sets the calendar-panel's bounds with the known dimensions. 58 | */ 59 | private void setCalendarPanelBounds() { 60 | setBounds(0, mainPanel.getTopPanelHeight(), calendarPanelWidth, calendarPanelHeight); 61 | } 62 | 63 | /** 64 | * Gets the width of the calendar-panel. 65 | * @return the width of the calendar-panel 66 | */ 67 | public Integer getCalendarPanelWidth() { 68 | return calendarPanelWidth; 69 | } 70 | 71 | /** 72 | * Gets the height of the calendar panel. 73 | * @return the height of the calendar panel 74 | */ 75 | public Integer getCalendarPanelHeight() { 76 | return calendarPanelHeight; 77 | } 78 | 79 | /** 80 | * Draws the month-panel. 81 | */ 82 | public void drawMonthPanel() { 83 | monthPanel = new MonthPanel(CalendarPanel.this); 84 | add(monthPanel); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/edu/avans/library/presentation/DayDetailPanel.java: -------------------------------------------------------------------------------- 1 | package edu.avans.library.presentation; 2 | 3 | import edu.avans.library.businesslogic.CalendarManager; 4 | import edu.avans.library.domain.Appointment; 5 | import javax.swing.*; 6 | import javax.swing.border.Border; 7 | import javax.swing.border.EmptyBorder; 8 | import javax.swing.JScrollPane; 9 | import java.awt.*; 10 | import java.awt.event.ActionEvent; 11 | import java.awt.event.ActionListener; 12 | import java.util.ArrayList; 13 | 14 | /** 15 | * The DayDetailPanel ensures the panel in which the details (appointments) of the active day will be placed. 16 | * It is placed within MainPanel. 17 | * @author Bram de Hart 18 | * @version 1.0 19 | * @see MainPanel 20 | */ 21 | public class DayDetailPanel extends JPanel { 22 | private Integer day, month, year; 23 | private Integer dayDetailPanelWidth, dayDetailPanelHeight; 24 | private MainPanel mainPanel; 25 | private CalendarManager manager = new CalendarManager(); 26 | private ArrayList appointments; 27 | private JScrollPane scrollPane; 28 | 29 | /** 30 | * Constructor. Creates an calendar object and inits the calendar-panel. 31 | */ 32 | public DayDetailPanel(MainPanel mainPanel) { 33 | this.mainPanel = mainPanel; 34 | month = mainPanel.mainFrame.calendar.month.getActiveMonth(); 35 | day = mainPanel.mainFrame.calendar.day.getActiveDay(); 36 | year = mainPanel.mainFrame.calendar.year.getActiveYear(); 37 | appointments = manager.getAppointments(mainPanel.mainFrame.calendar.getDate(month,day,year)); 38 | 39 | drawDayDetailPanel(); 40 | } 41 | 42 | /** 43 | * Draws the day-detail panel. 44 | */ 45 | private void drawDayDetailPanel() { 46 | setLayout(null); 47 | setBackground(Color.WHITE); 48 | setDayDetailPanelDimensions(); 49 | setDayDetailPanelBounds(); 50 | 51 | drawDayLabel(); 52 | drawAppointments(); 53 | } 54 | 55 | /** 56 | * Updates the day-detail panel dimensions and sets it's new bounds. 57 | */ 58 | public void resizeDayDetailPanel() { 59 | setDayDetailPanelDimensions(); 60 | setDayDetailPanelBounds(); 61 | } 62 | 63 | /** 64 | * Sets the day-detail panel's dimensions. 65 | */ 66 | private void setDayDetailPanelDimensions() { 67 | dayDetailPanelWidth = (int) (mainPanel.mainFrame.getContentPane().getWidth() * 0.2); 68 | dayDetailPanelHeight = mainPanel.mainFrame.getContentPane().getHeight(); 69 | } 70 | 71 | /** 72 | * Sets the day-detail panel's bounds with the known dimensions. 73 | */ 74 | private void setDayDetailPanelBounds() { 75 | setBounds((int) mainPanel.mainFrame.getContentPane().getWidth() - dayDetailPanelWidth, 0, dayDetailPanelWidth, dayDetailPanelHeight); 76 | //scrollPane.setBounds(0,mainPanel.getTopPanelHeight(),dayDetailPanelWidth, dayDetailPanelHeight - mainPanel.getTopPanelHeight()); 77 | } 78 | 79 | /** 80 | * Draws the weekday-name and month day heading. 81 | */ 82 | private void drawDayLabel() { 83 | String weekDayName = mainPanel.mainFrame.calendar.week.getWeekDayName(mainPanel.mainFrame.calendar.getDate(month, day, year)); 84 | JLabel dayLabel = new JLabel(weekDayName+" "+day); 85 | dayLabel.setBounds(15,10,dayDetailPanelWidth,50); 86 | dayLabel.setForeground(Color.decode("#333333")); 87 | dayLabel.setFont(new Font("Arial", Font.PLAIN, 30)); 88 | 89 | add(dayLabel); 90 | } 91 | 92 | /** 93 | * Redraws the day detail-panel 94 | */ 95 | public void redrawDayDetailPanel() { 96 | month = mainPanel.mainFrame.calendar.month.getActiveMonth(); 97 | day = mainPanel.mainFrame.calendar.day.getActiveDay(); 98 | year = mainPanel.mainFrame.calendar.year.getActiveYear(); 99 | appointments = manager.getAppointments(mainPanel.mainFrame.calendar.getDate(month,day,year)); 100 | 101 | removeAll(); 102 | drawDayDetailPanel(); 103 | validate(); 104 | repaint(); 105 | } 106 | 107 | /** 108 | * Draws each appointment with it's contents in the panel. 109 | */ 110 | private void drawAppointments() { 111 | JPanel appointmentsPanel = new JPanel(); 112 | appointmentsPanel.setLayout(new BoxLayout(appointmentsPanel, BoxLayout.Y_AXIS)); 113 | appointmentsPanel.setBackground(Color.WHITE); 114 | appointmentsPanel.setOpaque(true); 115 | 116 | scrollPane = new JScrollPane(appointmentsPanel); 117 | scrollPane.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, Color.decode("#E2E2E2"))); 118 | scrollPane.setOpaque(true); 119 | // set bounds 120 | scrollPane.setBounds(0,mainPanel.getTopPanelHeight(),dayDetailPanelWidth, dayDetailPanelHeight - mainPanel.getTopPanelHeight()); 121 | scrollPane.getVerticalScrollBar().setUnitIncrement(25); 122 | 123 | Integer appointmentsSize = appointments.size(); 124 | 125 | if(appointmentsSize > 0) { 126 | for (Integer i = 0; i < appointments.size(); i++) { 127 | Appointment appointment = appointments.get(i); 128 | 129 | Boolean hasLocation = true; 130 | Boolean hasDescription = true; 131 | if (appointment.location == null) { 132 | hasLocation = false; 133 | } 134 | if (appointment.description == null) { 135 | hasDescription = false; 136 | } 137 | 138 | // components 139 | Border spacingBorder = new EmptyBorder(0, 6, 0, 6); 140 | String startTime = appointment.startTime.toString(); 141 | startTime = startTime.substring(0, startTime.length() - 3); 142 | String endTime = appointment.endTime.toString(); 143 | endTime = endTime.substring(0, endTime.length() - 3); 144 | JLabel time = new JLabel(startTime+" - "+endTime); 145 | time.setBorder(spacingBorder); 146 | JLabel title = new JLabel(appointment.title); 147 | title.setBorder(spacingBorder); 148 | title.setFont(new Font("Arial", Font.BOLD, 14)); 149 | 150 | JButton deleteButton = new JButton("Delete"); 151 | deleteButton.addActionListener(new deleteAppointmentHandler(appointment.appointmentId, appointment.title)); 152 | 153 | // create panel and add components 154 | JPanel appointmentPanel = new JPanel(); 155 | appointmentPanel.setLayout(new BoxLayout(appointmentPanel, BoxLayout.Y_AXIS)); 156 | appointmentPanel.add(title); 157 | appointmentPanel.add(time); 158 | if (hasLocation) { 159 | JLabel location = new JLabel("Location: "+appointment.location); 160 | location.setBorder(spacingBorder); 161 | appointmentPanel.add(location); 162 | } 163 | if (hasDescription) { 164 | JLabel description = new JLabel("Notes: "+appointment.description); 165 | description.setBorder(spacingBorder); 166 | appointmentPanel.add(description); 167 | } 168 | appointmentPanel.add(deleteButton); 169 | 170 | appointmentPanel.setOpaque(false); 171 | appointmentPanel.setBorder(new EmptyBorder(10, 12, 10, 12)); 172 | appointmentsPanel.add(appointmentPanel); 173 | } 174 | } 175 | else { 176 | JLabel noResultsLabel = new JLabel("No events found"); 177 | noResultsLabel.setFont(new Font("Arial", Font.PLAIN, 14)); 178 | noResultsLabel.setBorder(new EmptyBorder(10, 12, 10, 12)); 179 | appointmentsPanel.add(noResultsLabel); 180 | } 181 | 182 | add(scrollPane); 183 | } 184 | 185 | /** 186 | * Inner class. Triggers an actionlistener when a delete button is clicked. 187 | */ 188 | class deleteAppointmentHandler implements ActionListener { 189 | private Integer appointmentId; 190 | private String appointmentName; 191 | 192 | /** 193 | * Constructor, stores the appointment ID. 194 | * @param appointmentId 195 | */ 196 | public deleteAppointmentHandler(Integer appointmentId, String appointmentName) { 197 | this.appointmentId = appointmentId; 198 | this.appointmentName = appointmentName; 199 | } 200 | 201 | /** 202 | * Deletes an appointment based on an appointment id 203 | * @param e 204 | */ 205 | public void actionPerformed(ActionEvent e) { 206 | int dialogResult = JOptionPane.showConfirmDialog(null, "Are you sure you want to delete the event \""+appointmentName+"\"?", "Delete event", JOptionPane.YES_NO_OPTION); 207 | 208 | if (dialogResult == JOptionPane.YES_OPTION) { 209 | // delete appointment 210 | manager.deleteAppointment(appointmentId); 211 | // redraw panels 212 | mainPanel.calendarPanel.monthPanel.redrawMonthPanel(); 213 | mainPanel.dayDetailPanel.redrawDayDetailPanel(); 214 | } 215 | } 216 | } 217 | } 218 | -------------------------------------------------------------------------------- /src/main/java/edu/avans/library/presentation/DayPanel.java: -------------------------------------------------------------------------------- 1 | package edu.avans.library.presentation; 2 | 3 | import edu.avans.library.businesslogic.CalendarManager; 4 | import edu.avans.library.domain.Appointment; 5 | import javax.swing.*; 6 | import javax.swing.border.*; 7 | import java.awt.*; 8 | import java.awt.event.ActionEvent; 9 | import java.awt.event.ActionListener; 10 | import java.io.File; 11 | import java.util.ArrayList; 12 | import java.util.Date; 13 | 14 | /** 15 | * The DayPanel ensures the user-interface panel for each day. 16 | * It is placed within MonthPanel. 17 | * @author Bram de Hart 18 | * @version 1.0 19 | * @see MonthPanel 20 | */ 21 | public class DayPanel extends JPanel { 22 | private CalendarPanel calendarPanel; 23 | public Integer day, month, year, index; 24 | private JButton viewAppointmentsButton, addAppointmentsButton; 25 | public ArrayList appointments; 26 | private Date date; 27 | private CalendarManager manager = new CalendarManager(); 28 | private Integer appointmentsCount; 29 | 30 | /** 31 | * Constructor. Initializes a day-panel. 32 | * @param day the day number 33 | * @param month the month number 34 | * @param year the year number 35 | * @param calendarPanel the calendarPanel it is part of 36 | * @param index the panel's index inside the month-panel 37 | */ 38 | public DayPanel(Integer day, Integer month, Integer year, CalendarPanel calendarPanel, Integer index) { 39 | this.day = day; 40 | this.month = month; 41 | this.year = year; 42 | this.calendarPanel = calendarPanel; 43 | this.index = index; 44 | date = calendarPanel.mainPanel.mainFrame.calendar.getDate(month, day, year); 45 | appointments = manager.getAppointments(date); 46 | appointmentsCount = appointments.size(); 47 | 48 | drawDayPanel(); 49 | } 50 | 51 | /** 52 | * Draws the day panel. 53 | */ 54 | private void drawDayPanel() { 55 | setLayout(new GridLayout(3,1)); 56 | setBackgroundColor(); 57 | setBorder(); 58 | 59 | JPanel dayTopPanel = new JPanel(); 60 | dayTopPanel.setBackground(new Color(0,0,0,0)); 61 | dayTopPanel.setLayout(new GridLayout(1,3)); 62 | 63 | // week number 64 | if (index % 7 == 1) { 65 | // first day of the week, show the weeknumber 66 | dayTopPanel.add(getStyledWeekNumber(getWeekNumber())); 67 | } 68 | else { 69 | dayTopPanel.add(new JLabel("")); 70 | } 71 | 72 | if (appointmentsCount > 0) { 73 | JLabel appointmentsCountLabel = new JLabel(appointmentsCount.toString()); 74 | appointmentsCountLabel.setFont(new Font("Arial", Font.BOLD, 16)); 75 | appointmentsCountLabel.setHorizontalAlignment(SwingConstants.CENTER); 76 | appointmentsCountLabel.setForeground(Color.WHITE); 77 | appointmentsCountLabel.setBackground(new Color(0,0,0,50)); 78 | appointmentsCountLabel.setOpaque(true); 79 | dayTopPanel.add(appointmentsCountLabel); 80 | } 81 | else { 82 | dayTopPanel.add(new JLabel("")); 83 | } 84 | 85 | // day number 86 | dayTopPanel.add(getStyledDayNumber(getDayNumber())); 87 | 88 | viewAppointmentsButton = new JButton("View"); 89 | viewAppointmentsButton.addActionListener(new viewAppointmentsButtonHandler()); 90 | addAppointmentsButton = new JButton("Add"); 91 | addAppointmentsButton.addActionListener(new addAppointmentsButtonHandler()); 92 | viewAppointmentsButton.setOpaque(false); 93 | addAppointmentsButton.setOpaque(false); 94 | 95 | add(dayTopPanel); 96 | add(addAppointmentsButton); 97 | add(viewAppointmentsButton); 98 | } 99 | 100 | /** 101 | * Returns a color code based on the appointments counts. 102 | * @param appointmentsCount the total appointments of a day 103 | * @return the color code 104 | */ 105 | private String getAppointmentsBackground(Integer appointmentsCount) { 106 | String backgroundHash = "#FFB312"; 107 | if (appointmentsCount > 5) { 108 | backgroundHash = "#FF6600"; 109 | if (appointmentsCount > 10) { 110 | backgroundHash = "#EE3230"; 111 | } 112 | } 113 | 114 | return backgroundHash; 115 | } 116 | 117 | /** 118 | * Sets the background color based on the week day. 119 | */ 120 | public void setBackgroundColor() { 121 | setBackground(Color.WHITE); 122 | 123 | // weekend day 124 | if (index % 7 == 0 || index % 7 == 1) { 125 | setBackground(Color.decode("#EEEEEE")); 126 | } 127 | 128 | // current day 129 | if (month == calendarPanel.mainPanel.mainFrame.calendar.month.getCurrentMonth() && 130 | day == calendarPanel.mainPanel.mainFrame.calendar.day.getCurrentDay() && 131 | year == calendarPanel.mainPanel.mainFrame.calendar.year.getCurrentYear() 132 | ) { 133 | setBackground(Color.decode("#1DA04A")); 134 | } 135 | 136 | // appointments 137 | if (appointmentsCount > 0) { 138 | setBackground(Color.decode(getAppointmentsBackground(appointmentsCount))); 139 | } 140 | 141 | // active day 142 | if (month == calendarPanel.mainPanel.mainFrame.calendar.month.getActiveMonth() && 143 | day == calendarPanel.mainPanel.mainFrame.calendar.day.getActiveDay() && 144 | year == calendarPanel.mainPanel.mainFrame.calendar.year.getActiveYear() 145 | ) { 146 | setBackground(Color.decode("#2E78F2")); 147 | } 148 | 149 | setOpaque(true); 150 | } 151 | 152 | /** 153 | * Gets the day number. 154 | * @return the day number 155 | */ 156 | public Integer getDayNumber() { 157 | return day; 158 | } 159 | 160 | /** 161 | * Styles the day number based on the month it is part of. 162 | * @param dayNumber the day number that needs to be styled 163 | * @return the styled day number as a label 164 | */ 165 | private JLabel getStyledDayNumber(Integer dayNumber) { 166 | JLabel dayLabel = new JLabel(this.day.toString()); 167 | dayLabel.setBorder(new EmptyBorder(10, 10, 10, 10)); 168 | dayLabel.setFont(new Font("Arial", Font.PLAIN, 16)); 169 | dayLabel.setHorizontalAlignment(SwingConstants.RIGHT); 170 | 171 | // days that aren't in the active month 172 | if (month != calendarPanel.mainPanel.mainFrame.calendar.month.getActiveMonth()) { 173 | dayLabel.setForeground(Color.decode("#B5B5B5")); 174 | } 175 | 176 | // current day, active day and days with appointments 177 | if (month == calendarPanel.mainPanel.mainFrame.calendar.month.getCurrentMonth() && 178 | day == calendarPanel.mainPanel.mainFrame.calendar.day.getCurrentDay() && 179 | year == calendarPanel.mainPanel.mainFrame.calendar.year.getCurrentYear() || 180 | month == calendarPanel.mainPanel.mainFrame.calendar.month.getActiveMonth() && 181 | day == calendarPanel.mainPanel.mainFrame.calendar.day.getActiveDay() && 182 | year == calendarPanel.mainPanel.mainFrame.calendar.year.getActiveYear() || 183 | appointmentsCount > 0 184 | ) { 185 | dayLabel.setForeground(Color.WHITE); 186 | } 187 | 188 | return dayLabel; 189 | } 190 | 191 | /** 192 | * Gets the week number the current day is part of. 193 | * @return the week number 194 | */ 195 | public Integer getWeekNumber() { 196 | return calendarPanel.mainPanel.mainFrame.calendar.week.getWeekNumber(calendarPanel.mainPanel.mainFrame.calendar.getDate(month, day, year)); 197 | } 198 | 199 | /** 200 | * Styles the week number based on the week it is part of. 201 | * @param weekNumber the week number that needs to be styled 202 | * @return the styles week number as a label 203 | */ 204 | private JLabel getStyledWeekNumber(Integer weekNumber) { 205 | JLabel weekLabel = new JLabel(weekNumber.toString()); 206 | weekLabel.setBorder(new EmptyBorder(10, 10, 10, 10)); 207 | weekLabel.setFont(new Font("Arial", Font.BOLD, 16)); 208 | weekLabel.setHorizontalAlignment(SwingConstants.LEFT); 209 | weekLabel.setForeground(Color.decode("#EF4A4A")); 210 | 211 | // styling if has appointments 212 | if (!appointments.isEmpty()) { 213 | weekLabel.setForeground(Color.WHITE); 214 | } 215 | 216 | // current day styling 217 | if (month == calendarPanel.mainPanel.mainFrame.calendar.month.getCurrentMonth() && 218 | day == calendarPanel.mainPanel.mainFrame.calendar.day.getCurrentDay() && 219 | year == calendarPanel.mainPanel.mainFrame.calendar.year.getCurrentYear() 220 | ) { 221 | weekLabel.setForeground(Color.WHITE); 222 | } 223 | 224 | // active day styling 225 | if (month == calendarPanel.mainPanel.mainFrame.calendar.month.getActiveMonth() && 226 | day == calendarPanel.mainPanel.mainFrame.calendar.day.getActiveDay() && 227 | year == calendarPanel.mainPanel.mainFrame.calendar.year.getActiveYear() 228 | ) { 229 | weekLabel.setForeground(Color.WHITE); 230 | } 231 | 232 | return weekLabel; 233 | } 234 | 235 | /** 236 | * Sets the border of the daypanel. 237 | */ 238 | public void setBorder() { 239 | setBorder(BorderFactory.createMatteBorder(1, 1, 0, 0, Color.decode("#E2E2E2"))); 240 | if (index % 7 == 1) { 241 | setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, Color.decode("#E2E2E2"))); 242 | } 243 | } 244 | 245 | /** 246 | * Inner class. Triggers an actionlistener when the viewAppointmentsButton is clicked. 247 | */ 248 | class viewAppointmentsButtonHandler implements ActionListener { 249 | /** 250 | * Updates the active date to the daypanel's one. 251 | * @param e 252 | */ 253 | public void actionPerformed(ActionEvent e) { 254 | // update active date 255 | calendarPanel.mainPanel.mainFrame.calendar.toDate(month+1, day, year); 256 | 257 | // redraw panels 258 | calendarPanel.mainPanel.setMonthYearLabelText(); 259 | calendarPanel.mainPanel.setDateFieldText(); 260 | calendarPanel.monthPanel.redrawMonthPanel(); 261 | calendarPanel.mainPanel.dayDetailPanel.redrawDayDetailPanel(); 262 | } 263 | } 264 | 265 | /** 266 | * Inner class. Triggers an actionlistener when the addAppointmentButton is clicked. 267 | */ 268 | class addAppointmentsButtonHandler implements ActionListener { 269 | /** 270 | * Opens new frame where a new appointment can be added. 271 | * @param e 272 | */ 273 | public void actionPerformed(ActionEvent e) { 274 | Integer offsetX = getLocationOnScreen().x; 275 | Integer offsetY = getLocationOnScreen().y; 276 | 277 | new AppointmentFrame(month, day, year, calendarPanel, offsetX, offsetY); 278 | } 279 | } 280 | } 281 | -------------------------------------------------------------------------------- /src/main/java/edu/avans/library/presentation/MainFrame.java: -------------------------------------------------------------------------------- 1 | package edu.avans.library.presentation; 2 | 3 | import edu.avans.library.domain.CCalendar; 4 | import edu.avans.library.businesslogic.CalendarManager; 5 | import javax.swing.*; 6 | import javax.swing.event.MenuEvent; 7 | import javax.swing.event.MenuListener; 8 | import java.awt.*; 9 | 10 | /** 11 | * The MainFrame ensures the main window of the calendar application. 12 | * It is called by edu.avans.library.main.Main. 13 | * @author Bram de Hart 14 | * @version 1.0 15 | * @see edu.avans.library.main.Main 16 | */ 17 | public class MainFrame extends JFrame { 18 | public Integer frameWidth, frameHeight; 19 | public MainPanel mainPanel; 20 | public CCalendar calendar; 21 | public CalendarManager manager; 22 | 23 | /** 24 | * Constructor. Calls the initialization of the frame, calendar and manager. 25 | */ 26 | public MainFrame() { 27 | calendar = new CCalendar(); 28 | manager = new CalendarManager(); 29 | initFrame(); 30 | } 31 | 32 | /** 33 | * Inits the frame. 34 | */ 35 | private void initFrame(){ 36 | new JFrame(); 37 | setFrameDimension(false); 38 | setTitle("Java Calendar"); 39 | //setSize(frameWidth,frameHeight); 40 | setSize(1300,800); 41 | setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 42 | setMinimumSize(new Dimension(1280, 800)); 43 | 44 | // add content to frame 45 | mainPanel = new MainPanel(MainFrame.this); 46 | setContentPane(mainPanel); 47 | setLocationRelativeTo(null); 48 | 49 | // add menubar 50 | //setJMenuBar(getCustomMenuBar()); 51 | 52 | setResizable(false); 53 | pack(); 54 | setVisible(true); 55 | } 56 | 57 | /** 58 | * Gets the height of the frame. 59 | * @return the height of the frame 60 | */ 61 | public Integer getMainFrameHeight() { 62 | return frameHeight; 63 | } 64 | 65 | /** 66 | * Gets the width of the frame. 67 | * @return the width of the frame 68 | */ 69 | public Integer getMainFrameWidth() { 70 | return frameWidth; 71 | } 72 | 73 | /** 74 | * Sets the frame dimension variables. 75 | * @param resized decides whether the frame dimensions are those of the users screen, or needed to be requested from the frame itself. 76 | */ 77 | public void setFrameDimension(boolean resized) { 78 | if (resized) { 79 | // window is being resized 80 | Dimension windowSize = getBounds().getSize(); 81 | frameWidth = (int) windowSize.getWidth(); 82 | frameHeight = (int) windowSize.getHeight(); 83 | } 84 | else { 85 | // first time startup 86 | Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 87 | frameWidth = (int) screenSize.getWidth(); 88 | frameHeight = (int) screenSize.getHeight(); 89 | } 90 | } 91 | 92 | /** 93 | * Draws a menubar in the MainFrame. 94 | * @return 95 | */ 96 | private JMenuBar getCustomMenuBar() { 97 | JMenuBar menuBar = new JMenuBar(); 98 | 99 | JMenu menu = new JMenu("About"); 100 | menu.addMenuListener(new MenuListener() { 101 | @Override 102 | public void menuSelected(MenuEvent e) { 103 | JOptionPane.showMessageDialog(null, 104 | "Java Calendar\n" + 105 | "Version: 1.0\n" + 106 | "Author: Bram de Hart\n" + 107 | "develop@bramdehart.nl\n\n"+ 108 | "github.com/bramdh\n" + 109 | "linkedin.com/in/bramdehart", "About Java Calendar", 110 | JOptionPane.PLAIN_MESSAGE); 111 | } 112 | @Override 113 | public void menuDeselected(MenuEvent e) { 114 | } 115 | @Override 116 | public void menuCanceled(MenuEvent e) { 117 | } 118 | }); 119 | 120 | menuBar.add(menu); 121 | 122 | return menuBar; 123 | } 124 | } -------------------------------------------------------------------------------- /src/main/java/edu/avans/library/presentation/MainPanel.java: -------------------------------------------------------------------------------- 1 | package edu.avans.library.presentation; 2 | import edu.avans.library.businesslogic.CalendarManager; 3 | 4 | import javax.swing.*; 5 | import java.awt.*; 6 | import java.awt.event.ComponentEvent; 7 | import java.awt.event.ComponentAdapter; 8 | import java.awt.event.ActionEvent; 9 | import java.awt.event.ActionListener; 10 | 11 | /** 12 | * The MainPanel ensures the main panel of the calendar application. 13 | * It contains the toppanel and CalendarPanel. 14 | * It is placed within MainFrame. 15 | * @author Bram de Hart 16 | * @version 1.0 17 | * @see CalendarPanel 18 | * @see MainFrame 19 | */ 20 | public class MainPanel extends JPanel { 21 | private static Integer TOP_PANEL_HEIGHT = 75; 22 | private Integer topPanelWidth; 23 | private JButton prevMonthButton, nextMonthButton, currentMonthButton; 24 | private JPanel topPanel, navigationButtonPanel; // for now private 25 | public CalendarPanel calendarPanel; 26 | public DayDetailPanel dayDetailPanel; 27 | public MainFrame mainFrame; 28 | private JLabel sundayLabel, mondayLabel, tuesdayLabel, wednesdayLabel, thursdayLabel, fridayLabel, saturdayLabel, monthYearLabel; 29 | public JTextField dateField; 30 | 31 | /** 32 | * Constructor. Sets the dimensions and content of the main-panel. 33 | * @param mainFrame is passed to have access to it's methods and variables. 34 | */ 35 | public MainPanel(MainFrame mainFrame) { 36 | this.mainFrame = mainFrame; 37 | topPanelWidth = mainFrame.getMainFrameWidth(); 38 | setLayout(null); 39 | addComponentListener(new resizeListener()); 40 | drawPanels(); 41 | } 42 | 43 | /** 44 | * Draws the panels that are part of the main-panel. 45 | */ 46 | private void drawPanels() { 47 | drawTopPanel(); 48 | drawDayDetailPanel(); 49 | drawCalendarPanel(); 50 | } 51 | 52 | /** 53 | * Draws the top-panel. 54 | */ 55 | private void drawTopPanel() { 56 | topPanel = new JPanel(); 57 | topPanel.setLayout(null); 58 | topPanel.setBorder(BorderFactory.createMatteBorder(0, 0, 0, 1, Color.decode("#E2E2E2"))); 59 | 60 | // buttons 61 | prevMonthButton = new JButton("<"); 62 | prevMonthButton.addActionListener(new prevMonthButtonHandler()); 63 | currentMonthButton = new JButton("Today"); 64 | currentMonthButton.addActionListener(new currentMonthButtonHandler()); 65 | nextMonthButton = new JButton(">"); 66 | nextMonthButton.addActionListener(new nextMonthButtonHandler()); 67 | dateField = new JTextField(); 68 | dateField.setHorizontalAlignment(JTextField.CENTER); 69 | setDateFieldText(); 70 | dateField.addActionListener(new dateFieldHandler()); 71 | 72 | navigationButtonPanel = new JPanel(); 73 | navigationButtonPanel.setBackground(Color.WHITE); 74 | navigationButtonPanel.setLayout(new GridLayout()); 75 | 76 | // weekday labels 77 | sundayLabel = new JLabel("Sun", SwingConstants.RIGHT); 78 | sundayLabel.setFont(new Font("Arial", Font.PLAIN, 16)); 79 | mondayLabel = new JLabel("Mon", SwingConstants.RIGHT); 80 | mondayLabel.setFont(new Font("Arial", Font.PLAIN, 16)); 81 | tuesdayLabel = new JLabel("Tue", SwingConstants.RIGHT); 82 | tuesdayLabel.setFont(new Font("Arial", Font.PLAIN, 16)); 83 | wednesdayLabel = new JLabel("Wed", SwingConstants.RIGHT); 84 | wednesdayLabel.setFont(new Font("Arial", Font.PLAIN, 16)); 85 | thursdayLabel = new JLabel("Thu", SwingConstants.RIGHT); 86 | thursdayLabel.setFont(new Font("Arial", Font.PLAIN, 16)); 87 | fridayLabel = new JLabel("Fri", SwingConstants.RIGHT); 88 | fridayLabel.setFont(new Font("Arial", Font.PLAIN, 16)); 89 | saturdayLabel = new JLabel("Sat", SwingConstants.RIGHT); 90 | saturdayLabel.setFont(new Font("Arial", Font.PLAIN, 16)); 91 | 92 | // draw the active month and year label 93 | monthYearLabel = new JLabel(); 94 | monthYearLabel.setForeground(Color.decode("#333333")); 95 | monthYearLabel.setFont(new Font("Arial", Font.PLAIN, 30)); 96 | setMonthYearLabelText(); 97 | 98 | topPanel.setBackground(Color.WHITE); 99 | setTopPanelBounds(); 100 | 101 | // add components 102 | navigationButtonPanel.add(dateField); 103 | navigationButtonPanel.add(prevMonthButton); 104 | navigationButtonPanel.add(currentMonthButton); 105 | navigationButtonPanel.add(nextMonthButton); 106 | topPanel.add(navigationButtonPanel); 107 | 108 | topPanel.add(sundayLabel); 109 | topPanel.add(mondayLabel); 110 | topPanel.add(tuesdayLabel); 111 | topPanel.add(wednesdayLabel); 112 | topPanel.add(thursdayLabel); 113 | topPanel.add(fridayLabel); 114 | topPanel.add(saturdayLabel); 115 | 116 | topPanel.add(monthYearLabel); 117 | add(topPanel); 118 | } 119 | 120 | /** 121 | * Resizes the panels. Is called by an resizeListener. 122 | */ 123 | private void resizePanels() { 124 | resizeTopPanel(); 125 | calendarPanel.resizeCalendarPanel(); 126 | dayDetailPanel.resizeDayDetailPanel(); 127 | } 128 | 129 | /** 130 | * Updates the top-panel dimensions and sets it's new bounds. 131 | */ 132 | private void resizeTopPanel() { 133 | topPanelWidth = (int) (mainFrame.getContentPane().getWidth() * 0.8); 134 | setTopPanelBounds(); 135 | } 136 | 137 | /** 138 | * Draws the calendar-panel. 139 | */ 140 | private void drawCalendarPanel() { 141 | calendarPanel = new CalendarPanel(MainPanel.this); 142 | add(calendarPanel); 143 | } 144 | 145 | /** 146 | * Draws the day-detail panel. 147 | */ 148 | private void drawDayDetailPanel() { 149 | dayDetailPanel = new DayDetailPanel(MainPanel.this); 150 | add(dayDetailPanel); 151 | } 152 | 153 | /** 154 | * Gets the width of the top-panel. 155 | * @return the width of the top-panel 156 | */ 157 | public Integer getTopPanelWidth() { 158 | return topPanelWidth; 159 | } 160 | 161 | /** 162 | * Gets the height of the top-panel. 163 | * @return the height of the top-panel 164 | */ 165 | public Integer getTopPanelHeight() { 166 | return TOP_PANEL_HEIGHT; 167 | } 168 | 169 | /** 170 | * Sets the top-panel's bounds with the known dimensions. 171 | */ 172 | private void setTopPanelBounds() { 173 | topPanel.setBounds(0, 0, topPanelWidth, TOP_PANEL_HEIGHT); 174 | Integer dayLabelWidth = topPanelWidth / 7; 175 | sundayLabel.setBounds(-5, 50, dayLabelWidth, 25); 176 | sundayLabel.setForeground(Color.decode("#BBBBBB")); 177 | mondayLabel.setBounds(dayLabelWidth-5, 50, dayLabelWidth, 25); 178 | tuesdayLabel.setBounds(2*dayLabelWidth-5, 50, dayLabelWidth, 25); 179 | wednesdayLabel.setBounds(3*dayLabelWidth-5, 50, dayLabelWidth, 25); 180 | thursdayLabel.setBounds(4*dayLabelWidth-5, 50, dayLabelWidth, 25); 181 | fridayLabel.setBounds(5*dayLabelWidth-5, 50, dayLabelWidth, 25); 182 | saturdayLabel.setBounds(6*dayLabelWidth-5, 50, dayLabelWidth, 25); 183 | saturdayLabel.setForeground(Color.decode("#BBBBBB")); 184 | monthYearLabel.setBounds(15,10,topPanelWidth/2,50); 185 | navigationButtonPanel.setBounds(topPanelWidth - 455, 12, 450, 30); 186 | } 187 | 188 | /** 189 | * Sets the text of monthYearLabel to the active month / year. 190 | */ 191 | public void setMonthYearLabelText() { 192 | monthYearLabel.setText(mainFrame.calendar.month.getMonthName(mainFrame.calendar.month.getActiveMonth())+" "+mainFrame.calendar.year.getActiveYear()); 193 | } 194 | 195 | /** 196 | * Sets the date field with new values. 197 | */ 198 | public void setDateFieldText() { 199 | dateField.setText(String.format("%02d",mainFrame.calendar.month.getActiveMonth()+1)+"/"+String.format("%02d",mainFrame.calendar.day.getActiveDay())+"/"+mainFrame.calendar.year.getActiveYear()); 200 | } 201 | 202 | /** 203 | * Inner class. Triggers an resizeListener when the window is resized. 204 | */ 205 | class resizeListener extends ComponentAdapter { 206 | /** 207 | * Sets new frame dimensions when the window is resized. 208 | * @param e 209 | */ 210 | public void componentResized(ComponentEvent e) { 211 | mainFrame.setFrameDimension(true); 212 | resizePanels(); 213 | } 214 | } 215 | 216 | /** 217 | * Inner class. Triggers an actionlistener when previous button is clicked. 218 | */ 219 | class prevMonthButtonHandler implements ActionListener { 220 | /** 221 | * Updates the month to the previous one. 222 | * @param e 223 | */ 224 | public void actionPerformed(ActionEvent e) { 225 | mainFrame.calendar.toPrevMonth(); 226 | setMonthYearLabelText(); 227 | setDateFieldText(); 228 | calendarPanel.monthPanel.redrawMonthPanel(); 229 | dayDetailPanel.redrawDayDetailPanel(); 230 | } 231 | } 232 | 233 | /** 234 | * Inner class. Triggers an actionlistener when next button is clicked. 235 | */ 236 | class nextMonthButtonHandler implements ActionListener { 237 | /** 238 | * Updates the month to the next one. 239 | * @param e 240 | */ 241 | public void actionPerformed(ActionEvent e) { 242 | mainFrame.calendar.toNextMonth(); 243 | setMonthYearLabelText(); 244 | setDateFieldText(); 245 | calendarPanel.monthPanel.redrawMonthPanel(); 246 | dayDetailPanel.redrawDayDetailPanel(); 247 | } 248 | } 249 | 250 | /** 251 | * Inner class. Triggers an actionlistener when current button is clicked. 252 | */ 253 | class currentMonthButtonHandler implements ActionListener { 254 | /** 255 | * Updates the month to the current one. 256 | * @param e 257 | */ 258 | public void actionPerformed(ActionEvent e) { 259 | mainFrame.calendar.toCurrentMonth(); 260 | setMonthYearLabelText(); 261 | setDateFieldText(); 262 | calendarPanel.monthPanel.redrawMonthPanel(); 263 | dayDetailPanel.redrawDayDetailPanel(); 264 | } 265 | } 266 | 267 | /** 268 | * Inner class. Triggers an actionlistener when current datefield is entered. 269 | */ 270 | class dateFieldHandler implements ActionListener { 271 | /** 272 | * Updates the year, month and day to the given one. 273 | * @param e 274 | */ 275 | public void actionPerformed(ActionEvent e) { 276 | String dateInput = dateField.getText(); 277 | if (dateInput.matches("([0-9]{2})/([0-9]{2})/([0-9]{4})")) { 278 | String[] dateInputs = dateInput.split("/"); 279 | Integer month = Integer.parseInt(dateInputs[0]); 280 | Integer day = Integer.parseInt(dateInputs[1]); 281 | Integer year = Integer.parseInt(dateInputs[2]); 282 | 283 | mainFrame.calendar.toDate(month, day, year); 284 | setMonthYearLabelText(); 285 | calendarPanel.monthPanel.redrawMonthPanel(); 286 | dayDetailPanel.redrawDayDetailPanel(); 287 | 288 | validate(); 289 | repaint(); 290 | } 291 | else { 292 | // show message dialog 293 | JOptionPane.showMessageDialog(null, 294 | "The entered date invalid.\n" + 295 | "Allowed format: mm/dd/yyyy.", 296 | "Invalid date", JOptionPane.ERROR_MESSAGE); 297 | } 298 | } 299 | } 300 | } 301 | -------------------------------------------------------------------------------- /src/main/java/edu/avans/library/presentation/MonthPanel.java: -------------------------------------------------------------------------------- 1 | package edu.avans.library.presentation; 2 | 3 | import javax.swing.*; 4 | import java.awt.*; 5 | import java.util.ArrayList; 6 | 7 | /** 8 | * The MonthPanel ensures the month user-interface panel. 9 | * It is placed within CalendarPanel. 10 | * @author Bram de Hart 11 | * @version 1.0 12 | * @see CalendarPanel 13 | */ 14 | public class MonthPanel extends JPanel { 15 | private static Integer DAYS_IN_MONTH_PANEL = 42; 16 | private Integer monthPanelWidth, monthPanelHeight; 17 | private CalendarPanel calendarPanel; 18 | private ArrayList dayPanelList = new ArrayList(); 19 | 20 | /** 21 | * Constructor. Sets the dimensions and content of the month-panel. 22 | * @param calendarPanel is passed to have access to it's methods and variables. 23 | */ 24 | public MonthPanel(CalendarPanel calendarPanel) { 25 | this.calendarPanel = calendarPanel; 26 | setMonthPanelDimensions(); 27 | setDayPanelList(); 28 | initMonthPanel(); 29 | } 30 | 31 | /** 32 | * Redraws the month-panel 33 | */ 34 | public void redrawMonthPanel() { 35 | emptyDayPanelList(); 36 | setDayPanelList(); 37 | removeAll(); 38 | initDayPanels(); 39 | 40 | validate(); 41 | repaint(); 42 | } 43 | 44 | /** 45 | * Emptys the day panel list 46 | */ 47 | public void emptyDayPanelList() { 48 | dayPanelList.clear(); 49 | } 50 | 51 | /** 52 | * Inits the month-panel. 53 | */ 54 | public void initMonthPanel() { 55 | setLayout(new GridLayout(6,7)); 56 | setBackground(Color.decode("#EEEEEE")); 57 | setBorder(BorderFactory.createMatteBorder(0, 0, 0, 1, Color.decode("#E2E2E2"))); 58 | setMonthPanelBounds(); 59 | initDayPanels(); 60 | } 61 | 62 | /** 63 | * Resizes the mont-panel. Is called by an resizeListener inside MainPanel. 64 | */ 65 | public void resizeMonthPanel() { 66 | setMonthPanelDimensions(); 67 | setMonthPanelBounds(); 68 | } 69 | 70 | /** 71 | * Sets the month-panel's dimensions. 72 | */ 73 | private void setMonthPanelDimensions() { 74 | monthPanelWidth = (int) (calendarPanel.getCalendarPanelWidth() * 0.8); 75 | monthPanelHeight = calendarPanel.mainPanel.mainFrame.getContentPane().getHeight() - calendarPanel.mainPanel.getTopPanelHeight(); 76 | } 77 | 78 | /** 79 | * Sets the month-panel's bounds with the known dimensions. 80 | */ 81 | private void setMonthPanelBounds() { 82 | setBounds(0, 0, monthPanelWidth, monthPanelHeight); 83 | } 84 | 85 | /** 86 | * Gets the width of the month-panel. 87 | * @return the width of the month-panel 88 | */ 89 | public Integer getMonthPanelWidth() { 90 | return monthPanelWidth; 91 | } 92 | 93 | /** 94 | * Gets the height of the month-panel. 95 | * @return the height of the month-panel 96 | */ 97 | public Integer getMonthPanelHeight() { 98 | return monthPanelHeight; 99 | } 100 | 101 | /** 102 | * Generates a list of days that needs to be displayed in the mont-panel. 103 | * May include some days of the previous and the next month. 104 | */ 105 | public void setDayPanelList() { 106 | 107 | // get first weekday of current month 108 | Integer firstWeekDay = calendarPanel.mainPanel.mainFrame.calendar.month.getFirstWeekDay( 109 | calendarPanel.mainPanel.mainFrame.calendar.month.getActiveMonth(), 110 | calendarPanel.mainPanel.mainFrame.calendar.year.getActiveYear() 111 | ); 112 | 113 | // get the number of days to be pre-added, based on the first weekday of the current month 114 | Integer previousCount = getDaysBefore(firstWeekDay); 115 | // get the number of days in the active month 116 | Integer mainCount = calendarPanel.mainPanel.mainFrame.calendar.month.getDayCount( 117 | calendarPanel.mainPanel.mainFrame.calendar.month.getActiveMonth(), 118 | calendarPanel.mainPanel.mainFrame.calendar.year.getActiveYear() 119 | ); 120 | // get the rest number of days to be added 121 | Integer restCount = getDaysAfter(previousCount, mainCount); 122 | 123 | // get the number of days in the previous month 124 | if (previousCount > 0) { 125 | Integer year = calendarPanel.mainPanel.mainFrame.calendar.year.getActiveYear(); 126 | Integer month = calendarPanel.mainPanel.mainFrame.calendar.month.getPreviousMonth(); 127 | Integer daysInPreviousMonth = 0; 128 | 129 | if (calendarPanel.mainPanel.mainFrame.calendar.month.getActiveMonth() == 0) { 130 | // active month is januari, previous month has also a previous year 131 | year = calendarPanel.mainPanel.mainFrame.calendar.year.getPreviousYear(); 132 | daysInPreviousMonth = calendarPanel.mainPanel.mainFrame.calendar.month.getDayCount(month, year); 133 | } 134 | else { 135 | daysInPreviousMonth = calendarPanel.mainPanel.mainFrame.calendar.month.getDayCount(month, year); 136 | } 137 | 138 | // add days of previous month in arraylist 139 | Integer index = 1; 140 | for (int day = daysInPreviousMonth - previousCount + 1; day <= daysInPreviousMonth; day++) { 141 | dayPanelList.add(new DayPanel(day, month, year, calendarPanel, index)); 142 | index ++; 143 | } 144 | } 145 | 146 | // add days of active month in arraylist 147 | for (int day = 1; day <= mainCount; day++) { 148 | dayPanelList.add(new DayPanel( 149 | day, 150 | calendarPanel.mainPanel.mainFrame.calendar.month.getActiveMonth(), 151 | calendarPanel.mainPanel.mainFrame.calendar.year.getActiveYear(), 152 | calendarPanel, 153 | previousCount+day 154 | )); 155 | } 156 | 157 | // add days of rest month in arraylist 158 | if (restCount > 0) { 159 | Integer year = calendarPanel.mainPanel.mainFrame.calendar.year.getActiveYear(); 160 | Integer month = calendarPanel.mainPanel.mainFrame.calendar.month.getNextMonth(); 161 | if (calendarPanel.mainPanel.mainFrame.calendar.month.getActiveMonth() == 11) { 162 | // active month is december, next month has also a next year 163 | year = calendarPanel.mainPanel.mainFrame.calendar.year.getNextYear(); 164 | } 165 | for (int day = 1; day <= restCount; day++) { 166 | dayPanelList.add(new DayPanel(day, month, year, calendarPanel, previousCount+mainCount+day)); 167 | } 168 | } 169 | } 170 | 171 | /** 172 | * Returns the daypanels of the month-panel view 173 | * @return list of daypanels 174 | */ 175 | private ArrayList getDayPanels() { 176 | return dayPanelList; 177 | } 178 | 179 | 180 | /** 181 | * Places every daypanel listed in the daypanel arralist in the monthpanel 182 | */ 183 | private void initDayPanels() { 184 | Integer listSize = dayPanelList.size(); 185 | for (int i = 0; i < listSize; i++) { 186 | add(dayPanelList.get(i)); 187 | } 188 | } 189 | 190 | /** 191 | * Calculates the number of days in the previous month that need to be pre-added in the dayPanelList 192 | * @oaram the start weekday of the current month 193 | * @return the number of days to be pre-added 194 | */ 195 | private Integer getDaysBefore(Integer firstWeekDay) { 196 | return firstWeekDay - 1; 197 | } 198 | 199 | /** 200 | * Calculates the number of days in the next month that need to be added in the dayPanelList 201 | * @param previousMonthDays the number of days of the previous month 202 | * @param currentMonthDays the number of days of the current month 203 | * @return the number of days to be added 204 | */ 205 | private Integer getDaysAfter(Integer previousMonthDays, Integer currentMonthDays) { 206 | return DAYS_IN_MONTH_PANEL - previousMonthDays - currentMonthDays; 207 | } 208 | 209 | } 210 | 211 | 212 | -------------------------------------------------------------------------------- /src/main/java/edu/avans/library/presentation/SpringUtilities.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1995, 2008, Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 8 | * - Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 11 | * - Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * - Neither the name of Oracle or the names of its 16 | * contributors may be used to endorse or promote products derived 17 | * from this software without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 20 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 21 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | package edu.avans.library.presentation; 33 | 34 | import javax.swing.*; 35 | import javax.swing.SpringLayout; 36 | import java.awt.*; 37 | 38 | /** 39 | * A 1.4 file that provides utility methods for 40 | * creating form- or grid-style layouts with SpringLayout. 41 | * These utilities are used by several programs, such as 42 | * SpringBox and SpringCompactGrid. 43 | */ 44 | public class SpringUtilities { 45 | /** 46 | * A debugging utility that prints to stdout the component's 47 | * minimum, preferred, and maximum sizes. 48 | */ 49 | public static void printSizes(Component c) { 50 | System.out.println("minimumSize = " + c.getMinimumSize()); 51 | System.out.println("preferredSize = " + c.getPreferredSize()); 52 | System.out.println("maximumSize = " + c.getMaximumSize()); 53 | } 54 | 55 | /** 56 | * Aligns the first rows * cols 57 | * components of parent in 58 | * a grid. Each component is as big as the maximum 59 | * preferred width and height of the components. 60 | * The parent is made just big enough to fit them all. 61 | * 62 | * @param rows number of rows 63 | * @param cols number of columns 64 | * @param initialX x location to start the grid at 65 | * @param initialY y location to start the grid at 66 | * @param xPad x padding between cells 67 | * @param yPad y padding between cells 68 | */ 69 | public static void makeGrid(Container parent, 70 | int rows, int cols, 71 | int initialX, int initialY, 72 | int xPad, int yPad) { 73 | SpringLayout layout; 74 | try { 75 | layout = (SpringLayout)parent.getLayout(); 76 | } catch (ClassCastException exc) { 77 | System.err.println("The first argument to makeGrid must use SpringLayout."); 78 | return; 79 | } 80 | 81 | Spring xPadSpring = Spring.constant(xPad); 82 | Spring yPadSpring = Spring.constant(yPad); 83 | Spring initialXSpring = Spring.constant(initialX); 84 | Spring initialYSpring = Spring.constant(initialY); 85 | int max = rows * cols; 86 | 87 | //Calculate Springs that are the max of the width/height so that all 88 | //cells have the same size. 89 | Spring maxWidthSpring = layout.getConstraints(parent.getComponent(0)). 90 | getWidth(); 91 | Spring maxHeightSpring = layout.getConstraints(parent.getComponent(0)). 92 | getHeight(); 93 | for (int i = 1; i < max; i++) { 94 | SpringLayout.Constraints cons = layout.getConstraints( 95 | parent.getComponent(i)); 96 | 97 | maxWidthSpring = Spring.max(maxWidthSpring, cons.getWidth()); 98 | maxHeightSpring = Spring.max(maxHeightSpring, cons.getHeight()); 99 | } 100 | 101 | //Apply the new width/height Spring. This forces all the 102 | //components to have the same size. 103 | for (int i = 0; i < max; i++) { 104 | SpringLayout.Constraints cons = layout.getConstraints( 105 | parent.getComponent(i)); 106 | 107 | cons.setWidth(maxWidthSpring); 108 | cons.setHeight(maxHeightSpring); 109 | } 110 | 111 | //Then adjust the x/y constraints of all the cells so that they 112 | //are aligned in a grid. 113 | SpringLayout.Constraints lastCons = null; 114 | SpringLayout.Constraints lastRowCons = null; 115 | for (int i = 0; i < max; i++) { 116 | SpringLayout.Constraints cons = layout.getConstraints( 117 | parent.getComponent(i)); 118 | if (i % cols == 0) { //start of new row 119 | lastRowCons = lastCons; 120 | cons.setX(initialXSpring); 121 | } else { //x position depends on previous component 122 | cons.setX(Spring.sum(lastCons.getConstraint(SpringLayout.EAST), 123 | xPadSpring)); 124 | } 125 | 126 | if (i / cols == 0) { //first row 127 | cons.setY(initialYSpring); 128 | } else { //y position depends on previous row 129 | cons.setY(Spring.sum(lastRowCons.getConstraint(SpringLayout.SOUTH), 130 | yPadSpring)); 131 | } 132 | lastCons = cons; 133 | } 134 | 135 | //Set the parent's size. 136 | SpringLayout.Constraints pCons = layout.getConstraints(parent); 137 | pCons.setConstraint(SpringLayout.SOUTH, 138 | Spring.sum( 139 | Spring.constant(yPad), 140 | lastCons.getConstraint(SpringLayout.SOUTH))); 141 | pCons.setConstraint(SpringLayout.EAST, 142 | Spring.sum( 143 | Spring.constant(xPad), 144 | lastCons.getConstraint(SpringLayout.EAST))); 145 | } 146 | 147 | /* Used by makeCompactGrid. */ 148 | private static SpringLayout.Constraints getConstraintsForCell( 149 | int row, int col, 150 | Container parent, 151 | int cols) { 152 | SpringLayout layout = (SpringLayout) parent.getLayout(); 153 | Component c = parent.getComponent(row * cols + col); 154 | return layout.getConstraints(c); 155 | } 156 | 157 | /** 158 | * Aligns the first rows * cols 159 | * components of parent in 160 | * a grid. Each component in a column is as wide as the maximum 161 | * preferred width of the components in that column; 162 | * height is similarly determined for each row. 163 | * The parent is made just big enough to fit them all. 164 | * 165 | * @param rows number of rows 166 | * @param cols number of columns 167 | * @param initialX x location to start the grid at 168 | * @param initialY y location to start the grid at 169 | * @param xPad x padding between cells 170 | * @param yPad y padding between cells 171 | */ 172 | public static void makeCompactGrid(Container parent, 173 | int rows, int cols, 174 | int initialX, int initialY, 175 | int xPad, int yPad) { 176 | SpringLayout layout; 177 | try { 178 | layout = (SpringLayout)parent.getLayout(); 179 | } catch (ClassCastException exc) { 180 | System.err.println("The first argument to makeCompactGrid must use SpringLayout."); 181 | return; 182 | } 183 | 184 | //Align all cells in each column and make them the same width. 185 | Spring x = Spring.constant(initialX); 186 | for (int c = 0; c < cols; c++) { 187 | Spring width = Spring.constant(0); 188 | for (int r = 0; r < rows; r++) { 189 | width = Spring.max(width, 190 | getConstraintsForCell(r, c, parent, cols). 191 | getWidth()); 192 | } 193 | for (int r = 0; r < rows; r++) { 194 | SpringLayout.Constraints constraints = 195 | getConstraintsForCell(r, c, parent, cols); 196 | constraints.setX(x); 197 | constraints.setWidth(width); 198 | } 199 | x = Spring.sum(x, Spring.sum(width, Spring.constant(xPad))); 200 | } 201 | 202 | //Align all cells in each row and make them the same height. 203 | Spring y = Spring.constant(initialY); 204 | for (int r = 0; r < rows; r++) { 205 | Spring height = Spring.constant(0); 206 | for (int c = 0; c < cols; c++) { 207 | height = Spring.max(height, 208 | getConstraintsForCell(r, c, parent, cols). 209 | getHeight()); 210 | } 211 | for (int c = 0; c < cols; c++) { 212 | SpringLayout.Constraints constraints = 213 | getConstraintsForCell(r, c, parent, cols); 214 | constraints.setY(y); 215 | constraints.setHeight(height); 216 | } 217 | y = Spring.sum(y, Spring.sum(height, Spring.constant(yPad))); 218 | } 219 | 220 | //Set the parent's size. 221 | SpringLayout.Constraints pCons = layout.getConstraints(parent); 222 | pCons.setConstraint(SpringLayout.SOUTH, y); 223 | pCons.setConstraint(SpringLayout.EAST, x); 224 | } 225 | } -------------------------------------------------------------------------------- /src/test/java/calendar/CalendarTest.java: -------------------------------------------------------------------------------- 1 | package calendar; 2 | 3 | import java.text.ParseException; 4 | import java.text.SimpleDateFormat; 5 | import java.util.Date; 6 | 7 | /** 8 | * Created by Bram on 04/12/2016. 9 | */ 10 | public class CalendarTest { 11 | /** 12 | * Returns the weeknumber based on a given date. 13 | * @return 14 | */ 15 | public Date getDate() { 16 | Integer month = 0; // zero based 17 | Integer day = 1; 18 | Integer year = 2016; 19 | 20 | SimpleDateFormat formatter = new SimpleDateFormat("M/d/yyyy"); 21 | String dateString = (month+1)+"/"+day+"/"+year; 22 | Date date = new Date(); 23 | 24 | try { 25 | date = formatter.parse(dateString); 26 | } catch (ParseException e) { 27 | System.out.println(e.getMessage()); 28 | } 29 | 30 | System.out.println(date); 31 | return date; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/day/DayTest.java: -------------------------------------------------------------------------------- 1 | package day; 2 | 3 | /** 4 | * Created by Bram on 04/12/2016. 5 | */ 6 | public class DayTest { 7 | /** 8 | * Sets the active day. 9 | */ 10 | public void setActiveDay() { 11 | Integer activeDay = 62; 12 | Integer monthDaysCount = 31; 13 | if (activeDay > monthDaysCount) { 14 | activeDay = monthDaysCount; 15 | } 16 | if (activeDay < 1) { 17 | activeDay = 1; 18 | } 19 | 20 | System.out.println(activeDay); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/month/MonthTest.java: -------------------------------------------------------------------------------- 1 | package month; 2 | 3 | import java.text.DateFormatSymbols; 4 | 5 | /** 6 | * Created by Bram on 05/12/2016. 7 | */ 8 | public class MonthTest { 9 | /** 10 | * Gets to month name. 11 | * @return the month name as a string 12 | */ 13 | public String getMonthName() { 14 | Integer month = 11; 15 | String monthName = new DateFormatSymbols().getMonths()[month]; 16 | System.out.println(monthName); 17 | return monthName; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/test/java/week/WeekTest.java: -------------------------------------------------------------------------------- 1 | package week; 2 | 3 | import java.text.SimpleDateFormat; 4 | import java.util.Calendar; 5 | import java.util.Date; 6 | 7 | /** 8 | * Created by Bram on 04/12/2016. 9 | */ 10 | public class WeekTest { 11 | /** 12 | * Gets the weekday name. 13 | * @return the weekday as a string 14 | */ 15 | public String getWeekDayName() { 16 | Date date = new Date(); 17 | String weekDayName = new SimpleDateFormat("EEEE").format(date); 18 | System.out.println(weekDayName); 19 | return weekDayName; 20 | } 21 | 22 | /** 23 | * Returns the weeknumber based on a given date. 24 | * @return 25 | */ 26 | public Integer getWeekNumber() { 27 | Date date = new Date(); 28 | Calendar cal = Calendar.getInstance(); 29 | cal.setTime(date); 30 | int week = cal.get(Calendar.WEEK_OF_YEAR); 31 | System.out.println(week); 32 | return week; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /target/classes/edu/avans/library/businesslogic/CalendarManager.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bramdehart/java-calendar/fc4973e95ded13790010163849fc4319d2715fb9/target/classes/edu/avans/library/businesslogic/CalendarManager.class -------------------------------------------------------------------------------- /target/classes/edu/avans/library/datastorage/AppointmentDAO.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bramdehart/java-calendar/fc4973e95ded13790010163849fc4319d2715fb9/target/classes/edu/avans/library/datastorage/AppointmentDAO.class -------------------------------------------------------------------------------- /target/classes/edu/avans/library/datastorage/CategoryDAO.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bramdehart/java-calendar/fc4973e95ded13790010163849fc4319d2715fb9/target/classes/edu/avans/library/datastorage/CategoryDAO.class -------------------------------------------------------------------------------- /target/classes/edu/avans/library/datastorage/DatabaseConnection.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bramdehart/java-calendar/fc4973e95ded13790010163849fc4319d2715fb9/target/classes/edu/avans/library/datastorage/DatabaseConnection.class -------------------------------------------------------------------------------- /target/classes/edu/avans/library/domain/Appointment.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bramdehart/java-calendar/fc4973e95ded13790010163849fc4319d2715fb9/target/classes/edu/avans/library/domain/Appointment.class -------------------------------------------------------------------------------- /target/classes/edu/avans/library/domain/CCalendar.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bramdehart/java-calendar/fc4973e95ded13790010163849fc4319d2715fb9/target/classes/edu/avans/library/domain/CCalendar.class -------------------------------------------------------------------------------- /target/classes/edu/avans/library/domain/CDay.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bramdehart/java-calendar/fc4973e95ded13790010163849fc4319d2715fb9/target/classes/edu/avans/library/domain/CDay.class -------------------------------------------------------------------------------- /target/classes/edu/avans/library/domain/CMonth.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bramdehart/java-calendar/fc4973e95ded13790010163849fc4319d2715fb9/target/classes/edu/avans/library/domain/CMonth.class -------------------------------------------------------------------------------- /target/classes/edu/avans/library/domain/CWeek.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bramdehart/java-calendar/fc4973e95ded13790010163849fc4319d2715fb9/target/classes/edu/avans/library/domain/CWeek.class -------------------------------------------------------------------------------- /target/classes/edu/avans/library/domain/CYear.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bramdehart/java-calendar/fc4973e95ded13790010163849fc4319d2715fb9/target/classes/edu/avans/library/domain/CYear.class -------------------------------------------------------------------------------- /target/classes/edu/avans/library/domain/Category.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bramdehart/java-calendar/fc4973e95ded13790010163849fc4319d2715fb9/target/classes/edu/avans/library/domain/Category.class -------------------------------------------------------------------------------- /target/classes/edu/avans/library/main/Main.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bramdehart/java-calendar/fc4973e95ded13790010163849fc4319d2715fb9/target/classes/edu/avans/library/main/Main.class -------------------------------------------------------------------------------- /target/classes/edu/avans/library/presentation/AppointmentFrame.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bramdehart/java-calendar/fc4973e95ded13790010163849fc4319d2715fb9/target/classes/edu/avans/library/presentation/AppointmentFrame.class -------------------------------------------------------------------------------- /target/classes/edu/avans/library/presentation/AppointmentPanel$saveAppointmentHandler.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bramdehart/java-calendar/fc4973e95ded13790010163849fc4319d2715fb9/target/classes/edu/avans/library/presentation/AppointmentPanel$saveAppointmentHandler.class -------------------------------------------------------------------------------- /target/classes/edu/avans/library/presentation/AppointmentPanel.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bramdehart/java-calendar/fc4973e95ded13790010163849fc4319d2715fb9/target/classes/edu/avans/library/presentation/AppointmentPanel.class -------------------------------------------------------------------------------- /target/classes/edu/avans/library/presentation/CalendarPanel.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bramdehart/java-calendar/fc4973e95ded13790010163849fc4319d2715fb9/target/classes/edu/avans/library/presentation/CalendarPanel.class -------------------------------------------------------------------------------- /target/classes/edu/avans/library/presentation/DayDetailPanel$deleteAppointmentHandler.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bramdehart/java-calendar/fc4973e95ded13790010163849fc4319d2715fb9/target/classes/edu/avans/library/presentation/DayDetailPanel$deleteAppointmentHandler.class -------------------------------------------------------------------------------- /target/classes/edu/avans/library/presentation/DayDetailPanel.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bramdehart/java-calendar/fc4973e95ded13790010163849fc4319d2715fb9/target/classes/edu/avans/library/presentation/DayDetailPanel.class -------------------------------------------------------------------------------- /target/classes/edu/avans/library/presentation/DayPanel$addAppointmentsButtonHandler.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bramdehart/java-calendar/fc4973e95ded13790010163849fc4319d2715fb9/target/classes/edu/avans/library/presentation/DayPanel$addAppointmentsButtonHandler.class -------------------------------------------------------------------------------- /target/classes/edu/avans/library/presentation/DayPanel$viewAppointmentsButtonHandler.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bramdehart/java-calendar/fc4973e95ded13790010163849fc4319d2715fb9/target/classes/edu/avans/library/presentation/DayPanel$viewAppointmentsButtonHandler.class -------------------------------------------------------------------------------- /target/classes/edu/avans/library/presentation/DayPanel.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bramdehart/java-calendar/fc4973e95ded13790010163849fc4319d2715fb9/target/classes/edu/avans/library/presentation/DayPanel.class -------------------------------------------------------------------------------- /target/classes/edu/avans/library/presentation/MainFrame$1.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bramdehart/java-calendar/fc4973e95ded13790010163849fc4319d2715fb9/target/classes/edu/avans/library/presentation/MainFrame$1.class -------------------------------------------------------------------------------- /target/classes/edu/avans/library/presentation/MainFrame.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bramdehart/java-calendar/fc4973e95ded13790010163849fc4319d2715fb9/target/classes/edu/avans/library/presentation/MainFrame.class -------------------------------------------------------------------------------- /target/classes/edu/avans/library/presentation/MainPanel$currentMonthButtonHandler.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bramdehart/java-calendar/fc4973e95ded13790010163849fc4319d2715fb9/target/classes/edu/avans/library/presentation/MainPanel$currentMonthButtonHandler.class -------------------------------------------------------------------------------- /target/classes/edu/avans/library/presentation/MainPanel$dateFieldHandler.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bramdehart/java-calendar/fc4973e95ded13790010163849fc4319d2715fb9/target/classes/edu/avans/library/presentation/MainPanel$dateFieldHandler.class -------------------------------------------------------------------------------- /target/classes/edu/avans/library/presentation/MainPanel$nextMonthButtonHandler.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bramdehart/java-calendar/fc4973e95ded13790010163849fc4319d2715fb9/target/classes/edu/avans/library/presentation/MainPanel$nextMonthButtonHandler.class -------------------------------------------------------------------------------- /target/classes/edu/avans/library/presentation/MainPanel$prevMonthButtonHandler.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bramdehart/java-calendar/fc4973e95ded13790010163849fc4319d2715fb9/target/classes/edu/avans/library/presentation/MainPanel$prevMonthButtonHandler.class -------------------------------------------------------------------------------- /target/classes/edu/avans/library/presentation/MainPanel$resizeListener.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bramdehart/java-calendar/fc4973e95ded13790010163849fc4319d2715fb9/target/classes/edu/avans/library/presentation/MainPanel$resizeListener.class -------------------------------------------------------------------------------- /target/classes/edu/avans/library/presentation/MainPanel.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bramdehart/java-calendar/fc4973e95ded13790010163849fc4319d2715fb9/target/classes/edu/avans/library/presentation/MainPanel.class -------------------------------------------------------------------------------- /target/classes/edu/avans/library/presentation/MonthPanel.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bramdehart/java-calendar/fc4973e95ded13790010163849fc4319d2715fb9/target/classes/edu/avans/library/presentation/MonthPanel.class -------------------------------------------------------------------------------- /target/classes/edu/avans/library/presentation/SpringUtilities.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bramdehart/java-calendar/fc4973e95ded13790010163849fc4319d2715fb9/target/classes/edu/avans/library/presentation/SpringUtilities.class -------------------------------------------------------------------------------- /target/test-classes/appointment/AppointmentTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bramdehart/java-calendar/fc4973e95ded13790010163849fc4319d2715fb9/target/test-classes/appointment/AppointmentTest.class -------------------------------------------------------------------------------- /target/test-classes/calendar/CalendarTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bramdehart/java-calendar/fc4973e95ded13790010163849fc4319d2715fb9/target/test-classes/calendar/CalendarTest.class -------------------------------------------------------------------------------- /target/test-classes/day/DayTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bramdehart/java-calendar/fc4973e95ded13790010163849fc4319d2715fb9/target/test-classes/day/DayTest.class -------------------------------------------------------------------------------- /target/test-classes/week/WeekTest.class: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bramdehart/java-calendar/fc4973e95ded13790010163849fc4319d2715fb9/target/test-classes/week/WeekTest.class --------------------------------------------------------------------------------