forked from nus-cs2103-AY1819S1/addressbook-level4
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request nus-cs2103-AY1819S1#86 from jiholim/master
[V1.3] UI Update & Refactor
- Loading branch information
Showing
16 changed files
with
220 additions
and
72 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
src/main/java/seedu/address/commons/events/ui/WishUpdatedEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package seedu.address.commons.events.ui; | ||
|
||
import seedu.address.commons.events.BaseEvent; | ||
|
||
/** | ||
* Represents a selection change in the Wish List Panel | ||
*/ | ||
public class WishUpdatedEvent extends BaseEvent { | ||
|
||
public WishUpdatedEvent() { | ||
|
||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getClass().getSimpleName(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package seedu.address.ui; | ||
|
||
import javafx.fxml.FXML; | ||
import javafx.scene.control.Label; | ||
import javafx.scene.layout.Region; | ||
|
||
/** | ||
* An UI component that displays information of a {@code Wish}. | ||
*/ | ||
public class SavingHistoryCell extends UiPart<Region> { | ||
|
||
private static final String FXML = "SavingHistoryCell.fxml"; | ||
|
||
/** | ||
* Note: Certain keywords such as "location" and "resources" are reserved keywords in JavaFX. | ||
* As a consequence, UI elements' variable names cannot be set to such keywords | ||
* or an exception will be thrown by JavaFX during runtime. | ||
* | ||
* @see <a href="https://github.com/se-edu/addressbook-level4/issues/336">The issue on WishBook level 4</a> | ||
*/ | ||
|
||
@FXML | ||
private Label history; | ||
|
||
public SavingHistoryCell(String savingHistory) { | ||
super(FXML); | ||
history.setText(savingHistory); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 66 additions & 3 deletions
69
src/main/java/seedu/address/ui/WishDetailSavingHistory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,102 @@ | ||
package seedu.address.ui; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.ListIterator; | ||
import java.util.logging.Logger; | ||
|
||
import com.google.common.eventbus.Subscribe; | ||
|
||
import javafx.collections.FXCollections; | ||
import javafx.collections.ObservableList; | ||
import javafx.fxml.FXML; | ||
import javafx.scene.control.ListCell; | ||
import javafx.scene.control.ListView; | ||
import javafx.scene.layout.Region; | ||
import seedu.address.commons.core.LogsCenter; | ||
import seedu.address.commons.events.ui.WishDataUpdatedEvent; | ||
import seedu.address.commons.events.ui.WishPanelSelectionChangedEvent; | ||
import seedu.address.model.WishTransaction; | ||
import seedu.address.model.wish.Wish; | ||
|
||
/** | ||
* Panel containing the detail of wish. | ||
*/ | ||
public class WishDetailSavingHistory extends UiPart<Region> { | ||
|
||
private static final String FXML = "WishDetailSavingHistory.fxml"; | ||
|
||
private final Logger logger = LogsCenter.getLogger(getClass()); | ||
|
||
public WishDetailSavingHistory() { | ||
private WishTransaction wishTransaction; | ||
private ArrayList savingHistoryList = new ArrayList(); | ||
private String id; | ||
|
||
@FXML | ||
private ListView<String> savingHistoryListView; | ||
|
||
public WishDetailSavingHistory(WishTransaction wishTransaction) { | ||
super(FXML); | ||
|
||
this.wishTransaction = wishTransaction; | ||
|
||
registerAsAnEventHandler(this); | ||
} | ||
|
||
private void setConnections(ObservableList<String> savingHistoryList) { | ||
savingHistoryListView.setItems(savingHistoryList); | ||
savingHistoryListView.setCellFactory(listView -> new WishDetailSavingHistory.SavingHistoryListViewCell()); | ||
} | ||
|
||
/** | ||
* Load the page that shows the detail of wish. | ||
*/ | ||
private void loadWishDetails(Wish wish) { | ||
this.savingHistoryList.clear(); | ||
this.id = wish.getId().toString(); | ||
|
||
ListIterator<Wish> entry = wishTransaction.getWishMap().get(wish.getId()).listIterator(1); | ||
|
||
while (entry.hasNext()) { | ||
Wish prevWish = wishTransaction.getWishMap().get(wish.getId()).get(entry.previousIndex()); | ||
double prevAmount = prevWish.getSavedAmount().value; | ||
double nextAmount = entry.next().getSavedAmount().value; | ||
double diff = nextAmount - prevAmount; | ||
savingHistoryList.add("Saved $" + String.format("%.2f", diff)); | ||
} | ||
|
||
Collections.reverse(savingHistoryList); | ||
|
||
ObservableList<String> oSavingHistoryList = FXCollections.observableArrayList(savingHistoryList); | ||
setConnections(oSavingHistoryList); | ||
} | ||
|
||
@Subscribe | ||
private void handleWishPanelSelectionChangedEvent(WishPanelSelectionChangedEvent event) { | ||
logger.info(LogsCenter.getEventHandlingLogMessage(event)); | ||
loadWishDetails(event.getNewSelection()); | ||
} | ||
|
||
@Subscribe | ||
private void handleWishDataUpdatedEvent(WishDataUpdatedEvent event) { | ||
logger.info(LogsCenter.getEventHandlingLogMessage(event)); | ||
if (this.id.equals(event.getNewData().getId().toString())) { | ||
loadWishDetails(event.getNewData()); | ||
} | ||
} | ||
|
||
/** | ||
* Custom {@code ListCell} that displays the graphics of a {@code String} using a {@code WishSavingHistoryCell}. | ||
*/ | ||
class SavingHistoryListViewCell extends ListCell<String> { | ||
@Override | ||
protected void updateItem(String savingHistory, boolean empty) { | ||
super.updateItem(savingHistory, empty); | ||
|
||
if (empty || savingHistory == null) { | ||
setGraphic(null); | ||
setText(null); | ||
} else { | ||
setGraphic(new SavingHistoryCell(savingHistory).getRoot()); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,20 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
|
||
<?import javafx.scene.control.Label?> | ||
<?import javafx.scene.layout.StackPane?> | ||
<?import javafx.geometry.Insets?> | ||
<?import javafx.scene.layout.GridPane?> | ||
<?import javafx.scene.layout.VBox?> | ||
<?import javafx.scene.web.WebView?> | ||
|
||
<StackPane xmlns:fx="http://javafx.com/fxml/1"> | ||
<WebView fx:id="browser"/> | ||
<VBox minHeight="400" GridPane.columnIndex="0"> | ||
<padding> | ||
<Insets top="5" bottom="5" /> | ||
</padding> | ||
<Label styleClass="detail_sub_title_label"> | ||
Product | ||
</Label> | ||
<WebView fx:id="browser"/> | ||
</VBox> | ||
</StackPane> |
Oops, something went wrong.