Skip to content

Commit

Permalink
Merge pull request #160 from Cary-Xx/finalDevelop
Browse files Browse the repository at this point in the history
Update ui
  • Loading branch information
Cary-Xx committed Nov 11, 2019
2 parents d7d6cfa + de3450a commit b066cc2
Show file tree
Hide file tree
Showing 6 changed files with 199 additions and 48 deletions.
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/MainApp.java
Expand Up @@ -48,7 +48,7 @@
*/
public class MainApp extends Application {

public static final Version VERSION = new Version(1, 2, 1, false);
public static final Version VERSION = new Version(1, 4, 0, false);
private static final Logger logger = LogsCenter.getLogger(MainApp.class);

protected Ui ui;
Expand Down
30 changes: 15 additions & 15 deletions src/main/java/seedu/address/ui/CommandBox.java
Expand Up @@ -36,7 +36,7 @@ public class CommandBox extends UiPart<Region> {
private int caretPos = 0;
private int anchorPos = 0;
private String newText;
private ListElementPointer historySnapshot;
private HistoryPointer historyPointer;

@FXML
private TextField commandTextField;
Expand All @@ -50,14 +50,14 @@ public CommandBox(CommandExecutor commandExecutor, List<String> history) {
this.history = history;
// calls #setStyleToDefault() whenever there is a change to the text of the command box.
commandTextField.textProperty().addListener((unused1, unused2, unused3) -> setStyleToDefault());
historySnapshot = new ListElementPointer(history);
historyPointer = new HistoryPointer(history);
handleHistoryNavigation();
caretChangeListener();
autoCompleteListener();
}

/*
Following is another approach, therefore commented out
Following is another approach for autocomplete, therefore commented out
*/
// /**
// * Handles the autofill event
Expand Down Expand Up @@ -197,7 +197,7 @@ private void autoCompleteListener() {
int indexSlash = targetText.lastIndexOf(separatorSlash);
String[] terms = null;
// Ignore separator
if (indexSpace == targetText.length() || indexSlash == targetText.length()) {
if (indexSpace == targetText.length() - 1 || indexSlash == targetText.length() - 1) {
return;
}
if (indexSpace > indexSlash) {
Expand Down Expand Up @@ -308,7 +308,7 @@ private void handleCommandEntered() {
try {
commandExecutor.execute(commandTextField.getText());
initHistory();
historySnapshot.next();
historyPointer.next();
commandTextField.setText("");
} catch (CommandException | ParseException e) {
initHistory();
Expand All @@ -317,13 +317,13 @@ private void handleCommandEntered() {
}

/**
* Initializes the history snapshot.
* Initializes a history pointer.
*/
private void initHistory() {
historySnapshot = new ListElementPointer(history);
historyPointer = new HistoryPointer(history);
// add an empty string to represent the most-recent end of historySnapshot, to be shown to
// the user if she tries to navigate past the most-recent end of the historySnapshot.
historySnapshot.add("");
historyPointer.add("");
}

/**
Expand Down Expand Up @@ -366,32 +366,32 @@ private void handleHistoryNavigation() {
* if there exists a previous input in {@code historySnapshot}
*/
private void navigateToPreviousInput() {
assert historySnapshot != null;
if (!historySnapshot.hasPrevious()) {
assert historyPointer != null;
if (!historyPointer.hasPrevious()) {
return;
}

replaceText(historySnapshot.previous());
getHistory(historyPointer.previous());
}

/**
* Updates the text field with the next input in {@code historySnapshot},
* if there exists a next input in {@code historySnapshot}
*/
private void navigateToNextInput() {
assert historySnapshot != null;
if (!historySnapshot.hasNext()) {
assert historyPointer != null;
if (!historyPointer.hasNext()) {
return;
}

replaceText(historySnapshot.next());
getHistory(historyPointer.next());
}

/**
* Sets {@code CommandBox}'s text field with {@code text} and
* positions the caret to the end of the {@code text}.
*/
private void replaceText(String text) {
private void getHistory(String text) {
commandTextField.setText(text);
commandTextField.positionCaret(commandTextField.getText().length());
}
Expand Down
Expand Up @@ -5,31 +5,26 @@
import java.util.NoSuchElementException;

/**
* Has a cursor that points to an element in the list, and is able to iterate through the list.
* This is different from {@code ListIterator}, which has a cursor that points in between elements.
* The {@code ListIterator}'s behaviour: when making alternating calls of {@code next()} and
* {@code previous()}, the same element is returned on both calls.
* In contrast, {@code ListElementPointer}'s behaviour: when making alternating calls of
* {@code next()} and {@code previous()}, the next and previous elements are returned respectively.
* This class is used to point to an element in the history list and iterate through the list.
*/
public class ListElementPointer {
private List<String> list;
public class HistoryPointer {
private List<String> historyLists;
private int index;

/**
* Constructs {@code ListElementPointer} which is backed by a defensive copy of {@code list}.
* Constructs {@code HistoryPointer} which is backed by a defensive copy of {@code list}.
* The cursor points to the last element in {@code list}.
*/
public ListElementPointer(List<String> list) {
this.list = new ArrayList<>(list);
index = this.list.size() - 1;
public HistoryPointer(List<String> list) {
this.historyLists = new ArrayList<>(list);
index = this.historyLists.size() - 1;
}

/**
* Appends {@code element} to the end of the list.
*/
public void add(String element) {
list.add(element);
public void add(String history) {
historyLists.add(history);
}

/**
Expand All @@ -56,29 +51,29 @@ public boolean hasCurrent() {
}

private boolean isWithinBounds(int index) {
return index >= 0 && index < list.size();
return index >= 0 && index < historyLists.size();
}

/**
* Returns the next element in the list and advances the cursor position.
* Points to the next element in the list and advances the cursor position.
* @throws NoSuchElementException if there is no more next element in the list.
*/
public String next() {
if (!hasNext()) {
throw new NoSuchElementException();
}
return list.get(++index);
return historyLists.get(++index);
}

/**
* Returns the previous element in the list and moves the cursor position backwards.
* Points the previous element in the list and moves the cursor position backwards.
* @throws NoSuchElementException if there is no more previous element in the list.
*/
public String previous() {
if (!hasPrevious()) {
throw new NoSuchElementException();
}
return list.get(--index);
return historyLists.get(--index);
}

/**
Expand All @@ -89,7 +84,7 @@ public String current() {
if (!hasCurrent()) {
throw new NoSuchElementException();
}
return list.get(index);
return historyLists.get(index);
}

@Override
Expand All @@ -100,12 +95,12 @@ public boolean equals(Object other) {
}

// instanceof handles nulls
if (!(other instanceof ListElementPointer)) {
if (!(other instanceof HistoryPointer)) {
return false;
}

// state check
ListElementPointer iterator = (ListElementPointer) other;
return list.equals(iterator.list) && index == iterator.index;
HistoryPointer iterator = (HistoryPointer) other;
return historyLists.equals(iterator.historyLists) && index == iterator.index;
}
}
2 changes: 1 addition & 1 deletion src/main/resources/view/MainWindow.fxml
Expand Up @@ -37,7 +37,7 @@
</MenuBar>

<StackPane fx:id="commandBoxPlaceholder" styleClass="pane-with-border" VBox.vgrow="NEVER"
maxHeight="125" minHeight="125" prefHeight="125">
maxHeight="115" minHeight="115" prefHeight="115">
<padding>
<Insets bottom="5" left="10" right="10" top="5"/>
</padding>
Expand Down
17 changes: 9 additions & 8 deletions src/main/resources/view/YellowTheme.css
Expand Up @@ -5,28 +5,28 @@

.label {
-fx-font-size: 11pt;
-fx-font-family: "Segoe UI Semibold";
-fx-font-family: "Comic Sans MS";
-fx-text-fill: #555555;
-fx-opacity: 0.9;
}

.label-bright {
-fx-font-size: 11pt;
-fx-font-family: "Segoe UI Semibold";
-fx-font-family: "Comic Sans MS";
-fx-text-fill: black;
-fx-opacity: 1;
}

.label-header {
-fx-font-size: 32pt;
-fx-font-family: "Segoe UI Light";
-fx-font-family: "Comic Sans MS";
-fx-text-fill: black;
-fx-opacity: 1;
}

.text-field {
-fx-font-size: 12pt;
-fx-font-family: "Segoe UI Semibold";
-fx-font-family: "Palatino";
}

.tab-pane {
Expand Down Expand Up @@ -117,13 +117,13 @@
}

.cell_big_label {
-fx-font-family: "Segoe UI Semibold";
-fx-font-family: "Palatino";
-fx-font-size: 16px;
-fx-text-fill: #010504;
}

.cell_small_label {
-fx-font-family: "Segoe UI";
-fx-font-family: "Palatino";
-fx-font-size: 13px;
-fx-text-fill: #010504;
}
Expand All @@ -144,7 +144,7 @@

.result-display {
-fx-background-color: transparent;
-fx-font-family: "Segoe UI Light";
-fx-font-family: "Comic Sans MS";
-fx-font-size: 13pt;
-fx-text-fill: black;
}
Expand Down Expand Up @@ -319,7 +319,7 @@
-fx-border-color: #E3D598 #E3D598 #000000 #E3D598;
-fx-border-insets: 0;
-fx-border-width: 1;
-fx-font-family: "Segoe UI Light";
-fx-font-family: "Comic Sans MS";
-fx-font-size: 13pt;
-fx-text-fill: black;
}
Expand Down Expand Up @@ -349,4 +349,5 @@

#expenseListTitle, #resultListTitle {
-fx-padding: 10px 10px 10px 10px ;
-fx-font-family: "Comic Sans MS";
}

0 comments on commit b066cc2

Please sign in to comment.