ctrl k
  • Clean-Water-Crowdsourcing/src/cs2340/cleanwater/controller/LoginController.java
    ■ ■ ■ ■ ■
    skipped 10 lines
    11 11   
    12 12  import java.io.IOException;
    13 13   
    14  -import static cs2340.cleanwater.controller.Utils.showAlert;
     14 +import static cs2340.cleanwater.controller.Utils.*;
    15 15   
    16 16  public class LoginController {
    17 17   
    skipped 58 lines
    76 76   }
    77 77   }
    78 78   
     79 + @FXML
     80 + private void openPressed() {
     81 + readFromFile(getFile(dialogStage, true));
     82 + }
     83 + 
     84 + @FXML
     85 + private void savePressed() {
     86 + writeToFile(getFile(dialogStage, false));
     87 + }
    79 88  }
    80 89   
  • Clean-Water-Crowdsourcing/src/cs2340/cleanwater/controller/MainController.java
    ■ ■ ■ ■ ■
    skipped 1 lines
    2 2   
    3 3  import cs2340.cleanwater.model.Model;
    4 4  import cs2340.cleanwater.model.Role;
     5 +import cs2340.cleanwater.model.SerializableModel;
    5 6  import javafx.fxml.FXML;
    6 7  import javafx.fxml.FXMLLoader;
    7 8  import javafx.scene.Scene;
    skipped 3 lines
    11 12  import javafx.scene.layout.BorderPane;
    12 13  import javafx.stage.Stage;
    13 14   
    14  -import java.io.IOException;
     15 +import java.io.*;
     16 + 
     17 +import static cs2340.cleanwater.controller.Utils.getFile;
     18 +import static cs2340.cleanwater.controller.Utils.writeToFile;
    15 19   
    16 20  public class MainController {
    17 21   
    skipped 182 lines
    200 204   loggedOff = true;
    201 205   dialogStage.close();
    202 206   
     207 + }
     208 + 
     209 + @FXML
     210 + private void savePressed() {
     211 + writeToFile(getFile(dialogStage, false));
    203 212   }
    204 213   
    205 214   /**
    skipped 12 lines
  • Clean-Water-Crowdsourcing/src/cs2340/cleanwater/controller/Utils.java
    ■ ■ ■ ■ ■ ■
    1 1  package cs2340.cleanwater.controller;
    2 2   
    3  -import cs2340.cleanwater.model.Condition;
    4  -import cs2340.cleanwater.model.OverallCondition;
    5  -import cs2340.cleanwater.model.Role;
    6  -import cs2340.cleanwater.model.Type;
     3 +import cs2340.cleanwater.model.*;
    7 4  import javafx.collections.FXCollections;
    8 5  import javafx.collections.ObservableList;
    9 6  import javafx.scene.control.Alert;
     7 +import javafx.stage.FileChooser;
     8 +import javafx.stage.Stage;
    10 9   
     10 +import java.io.*;
    11 11  import java.util.ArrayList;
    12 12  import java.util.Arrays;
    13 13  import java.util.List;
    skipped 77 lines
    91 91   showAlert("Information Error", "Incomplete Form", "You must fill in every part of the form");
    92 92   
    93 93   return notNull && locMatch;
     94 + }
     95 + 
     96 + public static void writeToFile(File file) {
     97 + try {
     98 + if (file != null) {
     99 + FileOutputStream fileOut = new FileOutputStream(file);
     100 + ObjectOutputStream out = new ObjectOutputStream(fileOut);
     101 + SerializableModel serial = new SerializableModel(Model.getInstance().getUsers(), Model.getInstance().getSourceReports(), Model.getInstance().getPurityReports(), Model.getInstance().getCurrentId());
     102 + out.writeObject(serial);
     103 + out.close();
     104 + fileOut.close();
     105 + }
     106 + } catch (IOException e) {
     107 + showAlert("File Open Error", "File Could Not Be Opened", "This file could not be opened for writing");
     108 + }
     109 + }
     110 + 
     111 + public static void readFromFile(File file) {
     112 + try {
     113 + if (file != null) {
     114 + FileInputStream fileIn = new FileInputStream(file);
     115 + ObjectInputStream in = new ObjectInputStream(fileIn);
     116 + SerializableModel serial = (SerializableModel) in.readObject();
     117 + in.close();
     118 + fileIn.close();
     119 + 
     120 + Model.getInstance().importSerial(serial);
     121 + }
     122 + } catch (IOException e) {
     123 + showAlert("File Read Error", "File Could Not Be Read", "This file could not be opened for reading");
     124 + } catch (ClassNotFoundException c) {
     125 + showAlert("File Read Error", "File Could Not Be Read", "This file is corrupt and cannot be read");
     126 + }
     127 + }
     128 + 
     129 + public static File getFile(Stage stage, boolean open) {
     130 + FileChooser fileChooser = new FileChooser();
     131 + FileChooser.ExtensionFilter cwFilter = new FileChooser.ExtensionFilter("Clean Water Files (*.cw)", "*.cw");
     132 + fileChooser.getExtensionFilters().add(cwFilter);
     133 + return open ? fileChooser.showOpenDialog(stage) : fileChooser.showSaveDialog(stage);
    94 134   }
    95 135  }
    96 136   
  • Clean-Water-Crowdsourcing/src/cs2340/cleanwater/model/Model.java
    ■ ■ ■ ■ ■
    skipped 5 lines
    6 6   
    7 7  import javax.print.attribute.standard.JobStateReason;
    8 8  import javax.xml.bind.DatatypeConverter;
     9 +import java.io.Serializable;
    9 10  import java.nio.charset.StandardCharsets;
    10 11  import java.security.MessageDigest;
    11 12  import java.security.NoSuchAlgorithmException;
    skipped 7 lines
    19 20  public class Model {
    20 21   
    21 22   private static final Model instance = new Model();
    22  - private final ObservableMap<String, User> users = FXCollections.observableHashMap();
    23  - private final ObservableList<Report> sourceReports = FXCollections.observableArrayList();
    24  - private final ObservableList<Report> purityReports = FXCollections.observableArrayList();
     23 + private ObservableMap<String, User> users = FXCollections.observableHashMap();
     24 + private ObservableList<Report> sourceReports = FXCollections.observableArrayList();
     25 + private ObservableList<Report> purityReports = FXCollections.observableArrayList();
    25 26   private User currentUser;
    26 27   private int currentId;
    27 28   
    skipped 33 lines
    61 62   return instance;
    62 63   }
    63 64   
     65 + public int getCurrentId() { return currentId; }
     66 + 
     67 + public ObservableMap getUsers() { return users; }
     68 + 
    64 69   /**
    65 70   * Gets the current logged in user
    66 71   *
    skipped 36 lines
    103 108   */
    104 109   public void logOff() {
    105 110   currentUser = null;
     111 + }
     112 + 
     113 + public void importSerial(SerializableModel newModel) {
     114 + this.users = newModel.getUsers();
     115 + this.sourceReports = newModel.getSourceReports();
     116 + this.purityReports = newModel.getPurityReports();
     117 + this.currentId = newModel.getCurrentId();
    106 118   }
    107 119   
    108 120   /**
    skipped 44 lines
  • Clean-Water-Crowdsourcing/src/cs2340/cleanwater/model/Report.java
    ■ ■ ■ ■ ■
    1 1  package cs2340.cleanwater.model;
    2 2   
     3 +import java.io.Serializable;
    3 4  import java.time.LocalTime;
    4 5   
    5 6  /**
    6 7   * Created by micah on 9/28/16.
    7 8   */
    8  -public abstract class Report {
     9 +public abstract class Report implements Serializable {
    9 10   protected LocalTime timestamp = LocalTime.now();
    10 11   final int id = Model.getInstance().newId();
    11 12   final User reporter = Model.getInstance().getCurrentUser();
    skipped 17 lines
  • Clean-Water-Crowdsourcing/src/cs2340/cleanwater/model/Role.java
    ■ ■ ■ ■ ■
    1 1  package cs2340.cleanwater.model;
    2 2   
    3  -public enum Role {
     3 +import java.io.Serializable;
     4 + 
     5 +public enum Role implements Serializable {
    4 6   USER("USER"),
    5 7   WORKER("WORKER"),
    6 8   MANAGER("MANAGER"),
    skipped 13 lines
  • Clean-Water-Crowdsourcing/src/cs2340/cleanwater/model/SerializableModel.java
    ■ ■ ■ ■ ■ ■
     1 +package cs2340.cleanwater.model;
     2 + 
     3 +import javafx.collections.FXCollections;
     4 +import javafx.collections.ObservableList;
     5 +import javafx.collections.ObservableMap;
     6 + 
     7 +import java.io.Serializable;
     8 +import java.util.ArrayList;
     9 +import java.util.HashMap;
     10 + 
     11 +/**
     12 + * Created by micah on 10/24/16.
     13 + */
     14 +public class SerializableModel implements Serializable {
     15 + 
     16 + private final HashMap<String, User> users;
     17 + private final ArrayList<Report> sourceReports;
     18 + private final ArrayList<Report> purityReports;
     19 + private int currentId;
     20 + 
     21 + private static final long serialVersionUID = 7839471155622776147L;
     22 + 
     23 + public SerializableModel(ObservableMap users, ObservableList sourceReports, ObservableList purityReports, int currentId) {
     24 + this.users = new HashMap(users);
     25 + this.sourceReports = new ArrayList(sourceReports);
     26 + this.purityReports = new ArrayList(purityReports);
     27 + this.currentId = currentId;
     28 + }
     29 + 
     30 + public ObservableMap getUsers() { return FXCollections.observableMap(users); }
     31 + 
     32 + public ObservableList getSourceReports() { return FXCollections.observableList(sourceReports); }
     33 + 
     34 + public ObservableList getPurityReports() { return FXCollections.observableList(purityReports); }
     35 + 
     36 + public int getCurrentId() { return currentId; }
     37 +}
     38 + 
  • Clean-Water-Crowdsourcing/src/cs2340/cleanwater/model/User.java
    ■ ■ ■ ■ ■
    1 1  package cs2340.cleanwater.model;
    2 2   
     3 +import java.io.Serializable;
     4 + 
    3 5  /**
    4 6   * Created by micah on 9/28/16.
    5 7   */
    6  -public class User {
     8 +public class User implements Serializable {
    7 9   String name;
    8 10   String user;
    9 11   String pass;
    skipped 103 lines
  • Clean-Water-Crowdsourcing/src/cs2340/cleanwater/view/Login.fxml
    ■ ■ ■ ■ ■ ■
    1 1  <?xml version="1.0" encoding="UTF-8"?>
    2 2   
    3  -<?import javafx.geometry.*?>
    4  -<?import javafx.scene.control.*?>
    5  -<?import javafx.scene.layout.*?>
    6  -<BorderPane xmlns:fx="http://javafx.com/fxml/1" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity"
    7  - prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.102-ea"
    8  - fx:controller="cs2340.cleanwater.controller.LoginController">
     3 +<?import javafx.geometry.Insets?>
     4 +<?import javafx.scene.control.Button?>
     5 +<?import javafx.scene.control.Label?>
     6 +<?import javafx.scene.control.Menu?>
     7 +<?import javafx.scene.control.MenuBar?>
     8 +<?import javafx.scene.control.MenuItem?>
     9 +<?import javafx.scene.control.PasswordField?>
     10 +<?import javafx.scene.control.TextField?>
     11 +<?import javafx.scene.layout.BorderPane?>
     12 +<?import javafx.scene.layout.ColumnConstraints?>
     13 +<?import javafx.scene.layout.GridPane?>
     14 +<?import javafx.scene.layout.RowConstraints?>
     15 +<?import javafx.scene.layout.VBox?>
     16 + 
     17 +<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.112-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="cs2340.cleanwater.controller.LoginController">
    9 18   <center>
    10 19   <VBox prefHeight="200.0" prefWidth="100.0" BorderPane.alignment="CENTER">
    11 20   <children>
    12 21   <GridPane>
    13 22   <columnConstraints>
    14  - <ColumnConstraints hgrow="SOMETIMES" maxWidth="292.0" minWidth="10.0" prefWidth="132.0"/>
    15  - <ColumnConstraints hgrow="SOMETIMES" maxWidth="468.0" minWidth="10.0" prefWidth="468.0"/>
     23 + <ColumnConstraints hgrow="SOMETIMES" maxWidth="292.0" minWidth="10.0" prefWidth="132.0" />
     24 + <ColumnConstraints hgrow="SOMETIMES" maxWidth="468.0" minWidth="10.0" prefWidth="468.0" />
    16 25   </columnConstraints>
    17 26   <rowConstraints>
    18  - <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
    19  - <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
     27 + <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
     28 + <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
    20 29   </rowConstraints>
    21 30   <children>
    22  - <Label text="User Name:" GridPane.halignment="RIGHT"/>
     31 + <Label text="User Name:" GridPane.halignment="RIGHT" />
    23 32   <Label text="Password:" GridPane.halignment="RIGHT" GridPane.rowIndex="1">
    24 33   <opaqueInsets>
    25  - <Insets/>
     34 + <Insets />
    26 35   </opaqueInsets>
    27 36   </Label>
    28 37   <TextField fx:id="usernameField" GridPane.columnIndex="1">
    29 38   <GridPane.margin>
    30  - <Insets left="10.0"/>
     39 + <Insets left="10.0" />
    31 40   </GridPane.margin>
    32 41   <opaqueInsets>
    33  - <Insets/>
     42 + <Insets />
    34 43   </opaqueInsets>
    35 44   </TextField>
    36 45   <PasswordField fx:id="passwordField" GridPane.columnIndex="1" GridPane.rowIndex="1">
    37 46   <GridPane.margin>
    38  - <Insets left="10.0"/>
     47 + <Insets left="10.0" />
    39 48   </GridPane.margin>
    40 49   <opaqueInsets>
    41  - <Insets/>
     50 + <Insets />
    42 51   </opaqueInsets>
    43 52   </PasswordField>
    44 53   </children>
    45 54   <padding>
    46  - <Insets left="30.0" right="30.0"/>
     55 + <Insets left="30.0" right="30.0" />
    47 56   </padding>
    48 57   </GridPane>
    49 58   <GridPane>
    50 59   <columnConstraints>
    51  - <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
    52  - <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0"/>
     60 + <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
     61 + <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
    53 62   </columnConstraints>
    54 63   <rowConstraints>
    55  - <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
     64 + <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
    56 65   </rowConstraints>
    57 66   <children>
    58  - <Button mnemonicParsing="false" onAction="#handleLoginPressed" text="Login"
    59  - GridPane.halignment="RIGHT">
     67 + <Button mnemonicParsing="false" onAction="#handleLoginPressed" text="Login" GridPane.halignment="RIGHT">
    60 68   <GridPane.margin>
    61  - <Insets right="10.0"/>
     69 + <Insets right="10.0" />
    62 70   </GridPane.margin>
    63 71   </Button>
    64  - <Button mnemonicParsing="false" onAction="#handleRegisterPressed" text="Register"
    65  - GridPane.columnIndex="1" GridPane.halignment="LEFT">
     72 + <Button mnemonicParsing="false" onAction="#handleRegisterPressed" text="Register" GridPane.columnIndex="1" GridPane.halignment="LEFT">
    66 73   <GridPane.margin>
    67  - <Insets left="10.0"/>
     74 + <Insets left="10.0" />
    68 75   </GridPane.margin>
    69 76   </Button>
    70 77   </children>
    71 78   <padding>
    72  - <Insets top="20.0"/>
     79 + <Insets top="20.0" />
    73 80   </padding>
    74 81   </GridPane>
    75 82   </children>
    76 83   <padding>
    77  - <Insets top="150.0"/>
     84 + <Insets top="150.0" />
    78 85   </padding>
    79 86   </VBox>
    80 87   </center>
     88 + <top>
     89 + <MenuBar BorderPane.alignment="CENTER">
     90 + <menus>
     91 + <Menu mnemonicParsing="false" text="File">
     92 + <items>
     93 + <MenuItem mnemonicParsing="false" onAction="#openPressed" text="Open..." />
     94 + <MenuItem mnemonicParsing="false" onAction="#savePressed" text="Save..." />
     95 + </items>
     96 + </Menu>
     97 + </menus>
     98 + </MenuBar>
     99 + </top>
    81 100  </BorderPane>
    82 101   
  • Clean-Water-Crowdsourcing/src/cs2340/cleanwater/view/Main.fxml
    ■ ■ ■ ■ ■ ■
    skipped 9 lines
    10 10  <?import javafx.scene.layout.VBox?>
    11 11  <?import javafx.scene.text.Font?>
    12 12   
     13 +<?import javafx.scene.control.MenuBar?>
     14 +<?import javafx.scene.control.Menu?>
     15 +<?import javafx.scene.control.MenuItem?>
    13 16  <BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.102-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="cs2340.cleanwater.controller.MainController">
    14 17   <center>
    15 18   <VBox alignment="CENTER" prefHeight="200.0" prefWidth="100.0" BorderPane.alignment="CENTER">
    skipped 38 lines
    54 57   </children>
    55 58   </VBox>
    56 59   </center>
     60 + <top>
     61 + <MenuBar BorderPane.alignment="CENTER">
     62 + <menus>
     63 + <Menu mnemonicParsing="false" text="File">
     64 + <items>
     65 + <MenuItem mnemonicParsing="false" onAction="#savePressed" text="Save..." />
     66 + </items>
     67 + </Menu>
     68 + </menus>
     69 + </MenuBar>
     70 + </top>
    57 71  </BorderPane>
    58 72   
Please wait...
Page is in error, reload to recover