diff --git a/.idea/misc.xml b/.idea/misc.xml index 07115cd..cc6eae0 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..7f573da --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,178 @@ + + + + + + + + + + + + + + + + + + + + { + "customColor": "", + "associatedIndex": 4 +} + + + + + + + + + + + + + + + + + + + + + + + + + + 1712774967671 + + + + + + + + + + + + + + + + + + + file://$PROJECT_DIR$/src/state/AwayModeOn.java + 21 + + + + + + + \ No newline at end of file diff --git a/out/production/SOEN343/.idea/workspace.xml b/out/production/SOEN343/.idea/workspace.xml new file mode 100644 index 0000000..81d1129 --- /dev/null +++ b/out/production/SOEN343/.idea/workspace.xml @@ -0,0 +1,139 @@ + + + + + + + + + + + + + + { + "customColor": "", + "associatedIndex": 4 +} + + + + { + "keyToString": { + "Application.GUIMain.executor": "Run", + "Application.SimDatabase.executor": "Run", + "RunOnceActivity.OpenProjectViewOnStart": "true", + "RunOnceActivity.ShowReadmeOnStart": "true", + "SHARE_PROJECT_CONFIGURATION_FILES": "true", + "UI_DESIGNER_EDITOR_MODE.UIDesignerToolWindowManager.WIDTH": "553", + "git-widget-placeholder": "AwayCloseDoorsWindows", + "kotlin-language-version-configured": "true", + "last_opened_file_path": "C:/Users/yasmi/Downloads/jdatepicker-1.3.4.jar", + "node.js.detected.package.eslint": "true", + "node.js.detected.package.tslint": "true", + "node.js.selected.package.eslint": "(autodetect)", + "node.js.selected.package.tslint": "(autodetect)", + "nodejs_package_manager_path": "npm", + "project.structure.last.edited": "Modules", + "project.structure.proportion": "0.14731099", + "project.structure.side.proportion": "0.17821783", + "vue.rearranger.settings.migration": "true" + }, + "keyToStringList": { + "DatabaseDriversLRU": [ + "mysql" + ] + } +} + + + + + + + + + + + + + + + + + + + + + + 1712774967671 + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Observer/Events/TemperatureEvent.java b/src/Observer/Events/TemperatureEvent.java new file mode 100644 index 0000000..6de235e --- /dev/null +++ b/src/Observer/Events/TemperatureEvent.java @@ -0,0 +1,16 @@ +package src.Observer.Events; + +import src.logic.SimulationParameter; + +public class TemperatureEvent extends Event { + private String eventType; + + public TemperatureEvent(String type, String eventType) { + super(type); + this.eventType = eventType; + } + + public String getEventType() { + return eventType; + } +} diff --git a/src/Observer/TempEvent.java b/src/Observer/TempEvent.java index 7b8baf6..a08e70f 100644 --- a/src/Observer/TempEvent.java +++ b/src/Observer/TempEvent.java @@ -17,9 +17,11 @@ public TempEvent(String type, SimulationParameter sp) { this.simulationParameter = sp; String date = sp.getDate().toString(); - int month = Integer.parseInt(date.substring(5,7)); - if(month >= 6 && month <=9) isSummer = true; - else isSummer = false; + int month = Integer.parseInt(date.substring(5, 7)); + if (month >= 6 && month <= 9) + isSummer = true; + else + isSummer = false; } public double getIndoorTemp() { @@ -34,7 +36,6 @@ public boolean getIsSummer() { return isSummer; } - public SimulationParameter getSimulationParameter() { return simulationParameter; } diff --git a/src/UI/SimParameterGUI.java b/src/UI/SimParameterGUI.java index 575b407..7a28787 100644 --- a/src/UI/SimParameterGUI.java +++ b/src/UI/SimParameterGUI.java @@ -18,7 +18,7 @@ import java.util.Date; import java.util.Properties; -public class SimParameterGUI extends JFrame{ +public class SimParameterGUI extends JFrame { private Controller controller = Controller.getController(); JFrame previousFrame = null; JFrame thisFrame = this; @@ -45,44 +45,45 @@ public class SimParameterGUI extends JFrame{ private ArrayList> typesOfZonesList = new ArrayList<>(); private Profile profile; - public SimParameterGUI(JFrame previousFrame, Profile profile){ + + public SimParameterGUI(JFrame previousFrame, Profile profile) { previousFrame = previousFrame; this.profile = profile; setUpButtons(); - zoneCreationPanel.setLayout(new GridLayout(0,controller.getRooms().size() + 3)); + zoneCreationPanel.setLayout(new GridLayout(0, controller.getRooms().size() + 3)); - //empty for spacing + // empty for spacing JLabel empty = new JLabel(""); zoneCreationPanel.add(empty); - //for every room type create a label for column - for (Room r: controller.getRooms()){ - JLabel roomLabel = new JLabel(String.valueOf(r.getType()) + " (id: " + r.getId() +")"); + // for every room type create a label for column + for (Room r : controller.getRooms()) { + JLabel roomLabel = new JLabel(String.valueOf(r.getType()) + " (id: " + r.getId() + ")"); roomLabel.setHorizontalAlignment(SwingConstants.CENTER); zoneCreationPanel.add(roomLabel); } - //for spacing + // for spacing JLabel empty1 = new JLabel("Temperature"); empty1.setHorizontalAlignment(SwingConstants.CENTER); zoneCreationPanel.add(empty1); - //empty1.setVisible(true); + // empty1.setVisible(true); - //for spacing + // for spacing JLabel typeLabel = new JLabel("Type of Zone"); typeLabel.setHorizontalAlignment(SwingConstants.CENTER); zoneCreationPanel.add(typeLabel); - //typeLabel.setVisible(false); + // typeLabel.setVisible(false); - //TO choose type of zones + // TO choose type of zones JLabel zoneLabel = new JLabel("Zone 1"); zoneLabel.setHorizontalAlignment(SwingConstants.CENTER); zoneCreationPanel.add(zoneLabel); - //add checkboxes for each room - for (Room r: controller.getRooms()){ + // add checkboxes for each room + for (Room r : controller.getRooms()) { JCheckBox c = new JCheckBox(); zones.add(c); c.setHorizontalAlignment(SwingConstants.CENTER); @@ -94,44 +95,43 @@ public SimParameterGUI(JFrame previousFrame, Profile profile){ tempField.setHorizontalAlignment(SwingConstants.CENTER); zoneCreationPanel.add(tempField); - JComboBox typesOfZones = new JComboBox<>(new String[]{"HEATING", "COOLING"}); + JComboBox typesOfZones = new JComboBox<>(new String[] { "HEATING", "COOLING" }); zoneCreationPanel.add(typesOfZones); typesOfZonesList.add(typesOfZones); - -// //for spacing -// JLabel empty3 = new JLabel(""); -// zoneCreationPanel.add(empty3); -// empty3.setVisible(false); - //this button will add rows as needed -// JButton addZoneButton = new JButton("Add Zone"); -// addZoneButton.addActionListener(new ActionListener() { -// @Override -// public void actionPerformed(ActionEvent e) { -// if(zoneCount < controller.getRooms().size()){ -// addZones(); -// }else{ -// System.out.println("cannot make more room then zones"); -// } -// -// } -// }); -// buttonsPanel.add(addZoneButton); - -// JButton doneZoneButton = new JButton("Done"); -// doneZoneButton.addActionListener(new ActionListener() { -// @Override -// public void actionPerformed(ActionEvent e) { -// listOfZones.add(zones); -// controller.setZones(listOfZones); -// controller.setTemperatureFile(filenameField.getText()); -// } -// }); -// buttonsPanel.add(doneZoneButton); + // //for spacing + // JLabel empty3 = new JLabel(""); + // zoneCreationPanel.add(empty3); + // empty3.setVisible(false); + // this button will add rows as needed + // JButton addZoneButton = new JButton("Add Zone"); + // addZoneButton.addActionListener(new ActionListener() { + // @Override + // public void actionPerformed(ActionEvent e) { + // if(zoneCount < controller.getRooms().size()){ + // addZones(); + // }else{ + // System.out.println("cannot make more room then zones"); + // } + // + // } + // }); + // buttonsPanel.add(addZoneButton); + + // JButton doneZoneButton = new JButton("Done"); + // doneZoneButton.addActionListener(new ActionListener() { + // @Override + // public void actionPerformed(ActionEvent e) { + // listOfZones.add(zones); + // controller.setZones(listOfZones); + // controller.setTemperatureFile(filenameField.getText()); + // } + // }); + // buttonsPanel.add(doneZoneButton); mainZonePanel.add(zoneCreationPanel, BorderLayout.CENTER); add(panel1); - //setSize(600,300); + // setSize(600,300); setUPDateSelection(); pack(); setTitle("Simulation Parameters"); @@ -140,35 +140,36 @@ public SimParameterGUI(JFrame previousFrame, Profile profile){ setDefaultCloseOperation(EXIT_ON_CLOSE); } - private void setUpButtons(){ + private void setUpButtons() { addZoneButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - if (zoneCount < controller.getRooms().size()){ - //listOfZones.add(zones); + if (zoneCount < controller.getRooms().size()) { + // listOfZones.add(zones); addZones(); - }else{ + } else { System.out.println("maximum number of zones created"); } } }); -// doneZoneButton.addActionListener(new ActionListener() { -// @Override -// public void actionPerformed(ActionEvent e) { -// listOfZones.add(zones); -// controller.setZones(listOfZones,temperatures,typesOfZonesList); -// } -// }); + // doneZoneButton.addActionListener(new ActionListener() { + // @Override + // public void actionPerformed(ActionEvent e) { + // listOfZones.add(zones); + // controller.setZones(listOfZones,temperatures,typesOfZonesList); + // } + // }); doneButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { listOfZones.add(zones); - controller.setZones(listOfZones,temperatures,typesOfZonesList); + controller.setZones(listOfZones, temperatures, typesOfZonesList); - controller.setSimulationParams(filenameField.getText(), (Date) datePicker.getModel().getValue(), (int) hourSpinner.getModel().getValue(), + controller.setSimulationParams(filenameField.getText(), (Date) datePicker.getModel().getValue(), + (int) hourSpinner.getModel().getValue(), (int) minuteSpinner.getModel().getValue(), (int) tempSpinner.getValue(), profile); Dashboard dash = new Dashboard(profile); @@ -178,35 +179,34 @@ public void actionPerformed(ActionEvent e) { }); } - private void setUPDateSelection(){ - SpinnerNumberModel spinHour = new SpinnerNumberModel(0,0,23,1); - SpinnerNumberModel spinMin = new SpinnerNumberModel(0,0,59,1); + private void setUPDateSelection() { + SpinnerNumberModel spinHour = new SpinnerNumberModel(0, 0, 23, 1); + SpinnerNumberModel spinMin = new SpinnerNumberModel(0, 0, 59, 1); hourSpinner.setModel(spinHour); minuteSpinner.setModel(spinMin); - UtilDateModel model = new UtilDateModel(); - model.setDate(2022,12,30); + model.setDate(2022, 12, 30); Properties p = new Properties(); p.put("text.today", "Today"); p.put("text.month", "Month"); p.put("text.year", "Year"); - JLabel l22=new JLabel("DATE :"); - l22.setBounds(100,350,100,20); + JLabel l22 = new JLabel("DATE :"); + l22.setBounds(100, 350, 100, 20); - JDatePanelImpl datePanel = new JDatePanelImpl(model,p); + JDatePanelImpl datePanel = new JDatePanelImpl(model, p); datePicker = new JDatePickerImpl(datePanel, new DateLabelFormatter()); add(datePicker, BorderLayout.SOUTH); - testPanel.add(l22); - datePicker.setBounds(220,350,120,30); + datePicker.setBounds(220, 350, 120, 30); testPanel.add(datePicker); dateAndtimePanel.add(testPanel); } + private void addZones() { zoneCount++; listOfZones.add(zones); @@ -227,26 +227,25 @@ private void addZones() { tempField.setHorizontalAlignment(SwingConstants.CENTER); zoneCreationPanel.add(tempField); - JComboBox typesOfZones = new JComboBox<>(new String[]{"HEATING", "COOLING"}); + JComboBox typesOfZones = new JComboBox<>(new String[] { "HEATING", "COOLING" }); zoneCreationPanel.add(typesOfZones); typesOfZonesList.add(typesOfZones); -// JLabel empty1 = new JLabel(""); -// zoneCreationPanel.add(empty1); -// empty1.setVisible(false); + // JLabel empty1 = new JLabel(""); + // zoneCreationPanel.add(empty1); + // empty1.setVisible(false); -// JLabel empty2 = new JLabel(""); -// zoneCreationPanel.add(empty2); -// empty2.setVisible(false); + // JLabel empty2 = new JLabel(""); + // zoneCreationPanel.add(empty2); + // empty2.setVisible(false); validate(); pack(); repaint(); } - public static void main(String[] args) { - new SimParameterGUI(null,null); + new SimParameterGUI(null, null); } } diff --git a/src/components/Room.java b/src/components/Room.java index 70d7b4d..a880cd6 100644 --- a/src/components/Room.java +++ b/src/components/Room.java @@ -1,6 +1,5 @@ package src.components; - import src.commands.*; import src.logic.Profile; @@ -9,6 +8,7 @@ import java.util.ArrayList; public class Room extends Component { + private double temperature = 100; private RoomType type; private Lights lights; private Windows windows; @@ -55,7 +55,6 @@ public Room(RoomType t, int windows, int lights, int doors, ArrayList o this.doors = null; } - this.numDoors = doors; if (windows > 0) this.windows = new Windows(); @@ -63,15 +62,19 @@ public Room(RoomType t, int windows, int lights, int doors, ArrayList o this.windows = null; } - public Room(){ + public Room() { this.identifier = generateUniqueId(); } + public double getTemperature() { + return temperature; + } + public boolean isInZone() { return isInZone; } - public void setIsInZone(boolean isInZone){ + public void setIsInZone(boolean isInZone) { this.isInZone = isInZone; } @@ -79,40 +82,40 @@ public int generateUniqueId() { return ++idCounter; } - public int getId(){ + public int getId() { return identifier; } - //default constructor - public void setType(RoomType t){ + // default constructor + public void setType(RoomType t) { type = t; } - public void setNumWindows(int windows){ + public void setNumWindows(int windows) { numWindows = windows; } - public void setNumLights(int lights){ + public void setNumLights(int lights) { numLights = lights; } - public void setNumDoors(int doors){ + public void setNumDoors(int doors) { numDoors = doors; } - public RoomType getType(){ + public RoomType getType() { return type; } - public int getNumWindows(){ + public int getNumWindows() { return numWindows; } - public int getNumLights(){ + public int getNumLights() { return numLights; } - public int getNumDoors(){ + public int getNumDoors() { return numDoors; } @@ -128,29 +131,32 @@ public Doors getDoors() { return doors; } - public ArrayList getUsers(){ + public ArrayList getUsers() { return this.users; } - public void addUserToRoom(Profile p){ - if (users == null){ + + public void addUserToRoom(Profile p) { + if (users == null) { users = new ArrayList<>(); } users.add(p); this.isMotionDetected(); } - public void setUsers(ArrayList p){ + + public void setUsers(ArrayList p) { this.users = p; this.isMotionDetected(); } - public boolean isOccupied(){ - if(users.size()==0 || users == null){ + public boolean isOccupied() { + if (users.size() == 0 || users == null) { return false; - }else{ + } else { return true; } } + public boolean getMotionDetected() { return this.motionDetected; } @@ -159,37 +165,39 @@ public boolean getMotionDetected() { @Override public String toString() { return "Room{" + - "type=" + type + - ", numWindows=" + numWindows + - ", numLights=" + numLights + - ", numDoors=" + numDoors + - //", occupiedBy=" + (users != null && users.length > 0 ? users[0].getName() : "none") + - ", identifier=" + identifier + - '}'; + "type=" + type + + ", numWindows=" + numWindows + + ", numLights=" + numLights + + ", numDoors=" + numDoors + + // ", occupiedBy=" + (users != null && users.length > 0 ? users[0].getName() : + // "none") + + ", identifier=" + identifier + + '}'; } - // Method to check and adjust lighting based on autoMode and user presence // If user clicks automode on layout, you constantly call this method // If user clicks automode off, you don't call this method public static void checkAndSetLighting(Room room, Profile caller) throws IOException { if (room.getLights() != null && room.getLights().getIsAutoMode()) { if (room.getUsers() != null) { - // Assuming switchLightsOn is a command that takes a Lights object and turns it on + // Assuming switchLightsOn is a command that takes a Lights object and turns it + // on room.setCommand(new TurnOnLightsCommand(room.getLights(), room.getUsers(), caller)); } else { - // Assuming switchLightsOff is a command that takes a Lights object and turns it off + // Assuming switchLightsOff is a command that takes a Lights object and turns it + // off room.setCommand(new TurnOffLightsCommand(room.getLights(), room.getUsers(), caller)); } room.executeCommand(); } } - public boolean isAwayMode(){ + public boolean isAwayMode() { return awayMode; } - public void setAwayMode(boolean awayMode){ + public void setAwayMode(boolean awayMode) { this.awayMode = awayMode; } @@ -214,7 +222,6 @@ public String getWindowsStatus() { return "Windows (" + numWindows + "): " + (windows.isOpen() ? "OPEN" : "CLOSED"); } - // Toggles the state of lights, doors, and windows public void toggleLights(Profile caller) throws IOException { if (lights != null) { @@ -245,8 +252,7 @@ public void toggleWindows(Profile caller) throws IOException { if (windows.isOpen()) { this.setCommand(new CloseWindowsCommand(windows, users, caller)); this.executeCommand(); - } - else { + } else { this.setCommand(new OpenWindowsCommand(windows, users, caller)); this.executeCommand(); } diff --git a/src/state/AwayModeOff.java b/src/state/AwayModeOff.java index f8e3ab7..cd619a4 100644 --- a/src/state/AwayModeOff.java +++ b/src/state/AwayModeOff.java @@ -38,6 +38,58 @@ public void checkIsOpen(ArrayList rooms, Profile profile) { } @Override + public void checkTemp(ArrayList rooms, Profile profile) { + // check if any room is above 135C degrees + for (Room room : rooms) { + if (room.getTemperature() > 135) { + // if any room is above 135C degrees, notify user with temp event + String eventString = "Away Mode - A room is above 135C degrees"; + System.out.println(eventString); + Event event = new TemperatureEvent("tempEvent", eventString); + + try { + shp.notifyConsoleOutputObserver(event); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + +@Override public void checkForMotion(ArrayList rooms, Profile profile){ + for (Room room : rooms) { + if (room.getMotionDetected()) { + + // Send notification of motion detected + motionNotification(); + + // Delay contacting authorities + int delay = this.shp.getAlertResponseTime(); + try { + Thread.sleep(delay * 1000); // Convert seconds to milliseconds + System.out.println("Authorities contacted " + delay + " seconds after motion detected."); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + } + + } + + } + + // Sending notification when motion is detected + private void motionNotification(){ + // if motion detected in any room + String eventString = "Away Mode - Motion Detected"; + System.out.println(eventString); + Event event = new ActionEvent("motionEvent", eventString); + try{ + shp.notifyConsoleOutputObserver(event); + } + catch (IOException e){ + e.printStackTrace(); + } } } diff --git a/src/state/AwayModeOn.java b/src/state/AwayModeOn.java index cd63f93..9049d9c 100644 --- a/src/state/AwayModeOn.java +++ b/src/state/AwayModeOn.java @@ -4,6 +4,7 @@ import src.Observer.Events.DoorEvent; import src.Observer.Events.WindowEvent; import src.Observer.Events.Event; +import src.Observer.Events.TemperatureEvent; import src.commands.CloseDoorsCommand; import src.commands.CloseWindowsCommand; import src.components.Room; @@ -20,6 +21,25 @@ public AwayModeOn(SHP shp) { } // TO BE IMPLEMENTED + @Override + public void checkTemp(ArrayList rooms, Profile profile) { + // check if any room is above 135C degrees + for (Room room : rooms) { + if (room.getTemperature() > 135) { + // if any room is above 135C degrees, notify user with temp event + String eventString = "Away Mode - A room is above 135C degrees"; + System.out.println(eventString); + Event event = new TemperatureEvent("tempEvent", eventString); + + try { + shp.notifyConsoleOutputObserver(event); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + @Override public void openDoors(ArrayList rooms, Profile profile) { diff --git a/src/state/SHP.java b/src/state/SHP.java index b4c79b9..3555d63 100644 --- a/src/state/SHP.java +++ b/src/state/SHP.java @@ -1,9 +1,7 @@ package src.state; import src.Observer.ConsoleOutputObserver; -import src.Observer.Events.DoorEvent; import src.Observer.Events.Event; -import src.Observer.Events.WindowEvent; import src.components.*; import src.logic.*; @@ -59,6 +57,7 @@ public void setState(State state) { private void startMonitoring() { scheduler.scheduleAtFixedRate(() -> { state.checkIsOpen(rooms, currentUser); + state.checkTemp(rooms, currentUser); }, 0, 5, TimeUnit.MINUTES); // Checks every 5 minutes } diff --git a/src/state/State.java b/src/state/State.java index 3fead11..1dbbc9d 100644 --- a/src/state/State.java +++ b/src/state/State.java @@ -15,5 +15,9 @@ public interface State { void closeWindows(ArrayList rooms, Profile profile); void checkIsOpen(ArrayList rooms, Profile profile); + + + void checkTemp(ArrayList rooms, Profile profile); + void checkForMotion(ArrayList rooms, Profile profile); }