Skip to content

Commit

Permalink
Merge pull request CS2113-AY1819S1-T09-1#33 from trufflepirate/fix
Browse files Browse the repository at this point in the history
Changed implementation of Machine Status
  • Loading branch information
trufflepirate authored Oct 10, 2018
2 parents ef5f865 + c91930b commit f9bf515
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 27 deletions.
8 changes: 4 additions & 4 deletions preferences.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"guiSettings" : {
"windowWidth" : 1550.4000244140625,
"windowHeight" : 838.4000244140625,
"windowWidth" : 1551.0,
"windowHeight" : 788.0,
"windowCoordinates" : {
"x" : -7,
"y" : -7
"x" : 86,
"y" : 142
}
},
"addressBookFilePath" : "data\\addressbook.xml",
Expand Down
15 changes: 11 additions & 4 deletions src/main/java/seedu/address/logic/parser/ParserUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import seedu.address.logic.parser.exceptions.ParseException;
import seedu.address.model.machine.Machine;
import seedu.address.model.machine.MachineName;
import seedu.address.model.machine.MachineStatus;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
Expand Down Expand Up @@ -146,13 +147,19 @@ public static MachineName parseMachineName(String machineName) throws ParseExcep
* depending if {@code machineStatus} equals true or false
*/

public static Boolean parseMachineStatus(String machineStatus) throws ParseException {
public static MachineStatus parseMachineStatus(String machineStatus) throws ParseException {
requireNonNull(machineStatus);
String trimMachineStatus = machineStatus.trim();
if ((!machineStatus.equals("ENABLED")) && (!machineStatus.equals("DISABLED"))) {

switch (trimMachineStatus) {
case "ENABLED":
return MachineStatus.ENABLED;

case "DISABLED":
return MachineStatus.DISABLED;

default:
throw new ParseException(Machine.MESSAGE_WRONG_STATUS);
}

return trimMachineStatus.equals("ENABLED");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import seedu.address.model.job.Job;
import seedu.address.model.machine.Machine;
import seedu.address.model.machine.MachineName;
import seedu.address.model.machine.MachineStatus;
import seedu.address.model.tag.Tag;


Expand All @@ -43,7 +44,7 @@ public AddMachineCommand parse(String args) throws ParseException {
}

MachineName name = ParserUtil.parseMachineName(argMultimap.getValue(PREFIX_NAME).get());
Boolean machineStatus = ParserUtil.parseMachineStatus(argMultimap.getValue(PREFIX_MACHINE_STATUS).get());
MachineStatus machineStatus = ParserUtil.parseMachineStatus(argMultimap.getValue(PREFIX_MACHINE_STATUS).get());
ArrayList<Job> jobs = new ArrayList<>();
Set<Tag> tags = new HashSet<>();
Machine machine = new Machine(name, jobs, tags, machineStatus);
Expand Down
16 changes: 5 additions & 11 deletions src/main/java/seedu/address/model/machine/Machine.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class Machine {
// Identity fields
private final MachineName machineName;
//TODO make status be more diverse, like enum
private final boolean status;
private final MachineStatus status;

// Data fields
//Name is a placeholder. To be replaced by Job class in the future
Expand All @@ -43,7 +43,7 @@ public class Machine {
/**
* Every field must be present and not null.
*/
public Machine(MachineName name, ArrayList<Job> jobs, Set<Tag> tags, boolean status) {
public Machine(MachineName name, ArrayList<Job> jobs, Set<Tag> tags, MachineStatus status) {
requireAllNonNull(name, jobs, tags);
this.machineName = name;
this.jobs.addAll(jobs);
Expand Down Expand Up @@ -122,7 +122,7 @@ public String toString() {
getJobs().forEach(builder::append);

builder.append(" Status: ");
builder.append(getStringStatus());
builder.append(getStatus().toString());
return builder.toString();
}

Expand All @@ -135,15 +135,9 @@ public static boolean isValidName(String test) {



public boolean getStatus() {
public MachineStatus getStatus() {
return status;
}

public String getStringStatus() {
if (getStatus()) {
return "Enabled";
} else {
return "Disabled";
}
}

}
8 changes: 8 additions & 0 deletions src/main/java/seedu/address/model/machine/MachineStatus.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package seedu.address.model.machine;

/**
* Represents a Machine Status.
*/
public enum MachineStatus {
ENABLED, DISABLED
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import seedu.address.model.job.JobNote;
import seedu.address.model.machine.Machine;
import seedu.address.model.machine.MachineName;
import seedu.address.model.machine.MachineStatus;
import seedu.address.model.person.Address;
import seedu.address.model.person.Email;
import seedu.address.model.person.Name;
Expand Down Expand Up @@ -57,7 +58,10 @@ public Job toModelType() throws IllegalValueException {

//TODO Remove hardcoding
Name name = new Name(jobName);
Machine machine = new Machine(new MachineName("JJ's printer"), new ArrayList<>(), new HashSet<>(), true);
Machine machine = new Machine(new MachineName("JJ's printer"),
new ArrayList<>(),
new HashSet<>(),
MachineStatus.ENABLED);
JobNote note = new JobNote("Empty note for now");
Person person = new Person(new Name("JunJie"),
new Phone("81184502"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import seedu.address.model.job.Job;
import seedu.address.model.machine.Machine;
import seedu.address.model.machine.MachineName;
import seedu.address.model.machine.MachineStatus;
import seedu.address.model.tag.Tag;
import seedu.address.storage.XmlAdaptedTag;

Expand All @@ -27,7 +28,7 @@ public class XmlAdaptedMachine {
@XmlElement(required = true)
private String machineName;
@XmlElement(required = true)
private Boolean status;
private MachineStatus status;

@XmlElement
private List<XmlAdaptedJobName> jobs = new ArrayList<>();
Expand All @@ -44,7 +45,7 @@ public XmlAdaptedMachine() {}
* Constructs an {@code XmlAdaptedMachine} with the given machine details.
*/
public XmlAdaptedMachine(String machineName,
Boolean status,
MachineStatus status,
List<XmlAdaptedJobName> jobs,
Set<XmlAdaptedTag> tags) {
this.machineName = machineName;
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/seedu/address/ui/machine/MachineCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import javafx.scene.layout.Region;
import javafx.scene.paint.Paint;
import seedu.address.model.machine.Machine;
import seedu.address.model.machine.MachineStatus;
import seedu.address.ui.UiPart;


Expand Down Expand Up @@ -46,26 +47,27 @@ public MachineCard(Machine machine, int displayIndex) {
this.machine = machine;
id.setText(displayIndex + ". ");
machineName.setText(machine.getName().fullName);
Label machineStatusLabel = new Label(machine.getStringStatus());
Label machineStatusLabel = new Label(machine.getStatus().toString());
machineStatusLabel.setStyle("-fx-font: 12 arial;"
+ "-fx-text-fill: black;"
+ "-fx-padding: 2;"
+ "-fx-text-alignment: center");
machineStatusLabel.setBackground(new Background(
new BackgroundFill(
Paint.valueOf(machine.getStatus() ? "#0ec10e" : "#dd0404"),
Paint.valueOf(machine.getStatus().equals(MachineStatus.ENABLED) ? "#0ec10e" : "#dd0404"),
new CornerRadii(2),
new javafx.geometry.Insets(0))));

Label machineAvailabilityLabel = new Label(machine.getStatus() ? "Available" : "Unavailable");
Label machineAvailabilityLabel = new Label(
machine.getStatus().equals(MachineStatus.ENABLED) ? "Available" : "Unavailable");
machineAvailabilityLabel.setStyle("-fx-font: 12 arial;"
+ "-fx-text-fill: black;"
+ "-fx-padding: 2;"
+ "-fx-text-alignment: center");

machineAvailabilityLabel.setBackground(new Background(
new BackgroundFill(
Paint.valueOf(machine.getStatus() ? "#0ec10e" : "#dd0404"),
Paint.valueOf(machine.getStatus().equals(MachineStatus.ENABLED) ? "#0ec10e" : "#dd0404"),
new CornerRadii(2),
new javafx.geometry.Insets(0))));

Expand Down

0 comments on commit f9bf515

Please sign in to comment.