Skip to content

Commit

Permalink
Merge pull request #26 from blaqkrow/v1.2-Implementing-Google-maps-+-…
Browse files Browse the repository at this point in the history
…extra-UI-elements

V1.2 Implementing Google maps + extra UI elements
  • Loading branch information
blaqkrow authored Oct 20, 2017
2 parents cddeb44 + f0101cf commit 049b207
Show file tree
Hide file tree
Showing 22 changed files with 295 additions and 39 deletions.
82 changes: 82 additions & 0 deletions docs/DeveloperGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,88 @@ Classes used by multiple components are in the `seedu.addressbook.commons` packa

This section describes some noteworthy details on how certain features are implemented.

=== Email Function

The email function allows a user to email the selected person by opening an email client on the user's
PC with the 'to:' field filled with the receiver's email.

This function has been mapped to `EmailButton`

Once a `PersonPanelSelectionChangedEvent` is raised, `EmailButton` will save the currently selected
email under the "email" attribute.
[source,java]
----
@Subscribe
private void handlePersonPanelSelectionChangedEvent(PersonPanelSelectionChangedEvent event) {
this.selectedEmail = event.getNewSelection().person.emailProperty().getValue().toString();
logger.info(LogsCenter.getEventHandlingLogMessage(event));
}
----


The following sequence diagram describes how `OpenEmailClient` passes in the "email" attribute to `Desktop`

image::OpenEmailClientSequenceDiagram.png[width="800"]


=== Mapping a command to a JavaFX Button

This section describes how a command can be mapped to a JavaFX button.

We will use the `DeleteButton` as an example but it can work for any command currently availble
in the application.

To initialise the button, we have to create a `StackPane` placeholder for it in `MainWindow`
[source,java]
----
@FXML
private StackPane deleteButtonPlaceholder;
----
Next, we create the `DeleteButton` class with the following constructor:
[source,java]
----
public DeleteButton(Logic logic, int selectedIn) {
super(FXML);
this.logic = logic;
this.selectedIndex = selectedIn;
registerAsAnEventHandler(this);
}
----

The `DeleteButton` will be instatiated in `MainWindow` where the
placeholder adds the corresponding button element:
[source,java]
----
deleteButton = new DeleteButton(logic, 0);
deleteButtonPlaceholder.getChildren().add(deleteButton.getRoot());
----

Once a `PersonPanelSelectionChangedEvent` is raised, `DeleteButton` will save the currently selected
index under the "selectedIndex" attribute.

The `DeleteButton` has an instance of `Logic` and `CommandResult` which performs a similar function
to `CommandBox`.

When the DeleteButton is pressed, it will be handled by the handleDeleteButtonPressed() function:

[source,java]
----
@FXML
private void handleDeleteButtonPressed() throws CommandException, ParseException {
CommandResult commandResult = logic.execute("delete " + getSelectedIndex());
logger.info("Result: " + commandResult.feedbackToUser);
}
----









// tag::undoredo[]
=== Undo/Redo mechanism

Expand Down
12 changes: 12 additions & 0 deletions docs/UserGuide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,18 @@ Another way to delete a contact in the list:
3. Selected person will be deleted from the list
****

=== Email a person

Opens an email client with the recipient's email address.

****
1. Select a person in the list
2. Click the "Email" Button
3. Proceed to compose email on email client
****



=== Selecting a person : `select`

Selects the person identified by the index number used in the last person listing. +
Expand Down
Binary file added docs/images/OpenEmailClientSequenceDiagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/UIClassDiagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/Ui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed docs/images/UiClassDiagram.png
Binary file not shown.
2 changes: 1 addition & 1 deletion src/main/java/seedu/address/commons/core/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class Config {
public static final String DEFAULT_CONFIG_FILE = "config.json";

// Config values customizable through config file
private String appTitle = "Address App";
private String appTitle = "ConnectUs";
private Level logLevel = Level.INFO;
private String userPrefsFilePath = "preferences.json";

Expand Down
12 changes: 7 additions & 5 deletions src/main/java/seedu/address/ui/BrowserPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
public class BrowserPanel extends UiPart<Region> {

public static final String DEFAULT_PAGE = "default.html";
public static final String GOOGLE_SEARCH_URL_PREFIX = "https://www.google.com.sg/search?safe=off&q=";
public static final String GOOGLE_SEARCH_URL_SUFFIX = "&cad=h";
//public static final String GOOGLE_SEARCH_URL_PREFIX = "https://www.google.com.sg/search?safe=off&q=";
public static final String GOOGLE_SEARCH_URL_PREFIX = "https://www.google.com.sg/maps/place/";
//public static final String GOOGLE_SEARCH_URL_SUFFIX = "&cad=h";

private static final String FXML = "BrowserPanel.fxml";

Expand All @@ -33,7 +34,7 @@ public class BrowserPanel extends UiPart<Region> {

public BrowserPanel() {
super(FXML);

browser.getEngine().setUserAgent(DEFAULT_PAGE.replace("Macintosh‌​; ", ""));
// To prevent triggering events for typing inside the loaded Web page.
getRoot().setOnKeyPressed(Event::consume);

Expand All @@ -42,8 +43,9 @@ public BrowserPanel() {
}

private void loadPersonPage(ReadOnlyPerson person) {
loadPage(GOOGLE_SEARCH_URL_PREFIX + person.getName().fullName.replaceAll(" ", "+")
+ GOOGLE_SEARCH_URL_SUFFIX);
browser.getEngine().setUserAgent("Mozilla/5.0 "
+ "(Windows NT x.y; Win64; x64; rv:10.0) Gecko/20100101 Firefox/10.0");
loadPage(GOOGLE_SEARCH_URL_PREFIX + person.getAddress().toString().replaceAll(" ", "+"));
}

public void loadPage(String url) {
Expand Down
51 changes: 51 additions & 0 deletions src/main/java/seedu/address/ui/EmailButton.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package seedu.address.ui;

import java.io.IOException;
import java.util.logging.Logger;

import com.google.common.eventbus.Subscribe;

import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.layout.Region;
import seedu.address.commons.core.LogsCenter;
import seedu.address.commons.events.ui.PersonPanelSelectionChangedEvent;
import seedu.address.logic.commands.exceptions.CommandException;
import seedu.address.logic.parser.exceptions.ParseException;

/**
* The UI component that is responsible for emailing the selected person.
*/
public class EmailButton extends UiPart<Region> {

public static final String ERROR_STYLE_CLASS = "error";
private static final String FXML = "EmailButton.fxml";

private final Logger logger = LogsCenter.getLogger(CommandBox.class);
private String selectedEmail = "";

@FXML
private Button emailButton;
public EmailButton() {
super(FXML);
registerAsAnEventHandler(this);
}

/**
* Handles the Email button pressed event.
*/
@FXML
private void handleEmailButtonPressed() throws CommandException, ParseException, IOException {
OpenEmailClient emailClient = new OpenEmailClient(this.selectedEmail);
emailClient.sendMail();
}

@Subscribe
private void handlePersonPanelSelectionChangedEvent(PersonPanelSelectionChangedEvent event) {
this.selectedEmail = event.getNewSelection().person.emailProperty().getValue().toString();
logger.info(LogsCenter.getEventHandlingLogMessage(event));
}



}
8 changes: 7 additions & 1 deletion src/main/java/seedu/address/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*/
public class MainWindow extends UiPart<Region> {

private static final String ICON = "/images/address_book_32.png";
private static final String ICON = "/images/connectus_icon.png";
private static final String FXML = "MainWindow.fxml";
private static final int MIN_HEIGHT = 600;
private static final int MIN_WIDTH = 450;
Expand All @@ -47,6 +47,7 @@ public class MainWindow extends UiPart<Region> {
private Config config;
private UserPrefs prefs;
private DeleteButton deleteButton;
private EmailButton emailButton;

@FXML
private VBox vBox;
Expand Down Expand Up @@ -81,6 +82,9 @@ public class MainWindow extends UiPart<Region> {
@FXML
private StackPane deleteButtonPlaceholder;

@FXML
private StackPane emailButtonPlaceholder;

public MainWindow(Stage primaryStage, Config config, UserPrefs prefs, Logic logic) {
super(FXML);

Expand Down Expand Up @@ -149,6 +153,8 @@ void fillInnerParts() {

deleteButton = new DeleteButton(logic, 0);
deleteButtonPlaceholder.getChildren().add(deleteButton.getRoot());
emailButton = new EmailButton();
emailButtonPlaceholder.getChildren().add(emailButton.getRoot());

browserPanel = new BrowserPanel();
browserPlaceholder.getChildren().add(browserPanel.getRoot());
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/seedu/address/ui/OpenEmailClient.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package seedu.address.ui;

import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;


/**
* Handles the opening of email client
*/
public class OpenEmailClient {
private Desktop desktop = Desktop.getDesktop();
private String mailTo;

/**
* Handles the opening of email client
*/
public OpenEmailClient(String mailTo) {
this.mailTo = mailTo.trim();
}

public void setMail (String m) {
mailTo = m;
}
/**
* Handles the sending mail
*/
public void sendMail () throws IOException {

URI uri = URI.create("mailto:" + this.mailTo);
desktop.mail(uri);

}
}
1 change: 1 addition & 0 deletions src/main/java/seedu/address/ui/PersonListPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public PersonListPanel(ObservableList<ReadOnlyPerson> personList) {
private void setConnections(ObservableList<ReadOnlyPerson> personList) {
ObservableList<PersonCard> mappedList = EasyBind.map(
personList, (person) -> new PersonCard(person, personList.indexOf(person) + 1));
//create a new personcard for each person added to the list
personListView.setItems(mappedList);
personListView.setCellFactory(listView -> new PersonListViewCell());
setEventHandlerForSelectionChangeEvent();
Expand Down
Binary file added src/main/resources/images/connectus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/images/connectus_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions src/main/resources/view/DarkTheme.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,30 @@
background-color: #383838; /* Used in the default.html file */
}

body {
-fx-background-color: derive(#1d1d1d, 20%);
background-color: #383838; /* Used in the default.html file */
}

h1 {
font-size: 32pt;
font-family: "Segoe UI", Helvetica, Arial, sans-serif;
text-fill: white;
color: white;
}

h2 {
font-size: 20pt;
font-family: "Segoe UI", Helvetica, Arial, sans-serif;
text-fill: white;
color: white;
}

.welcomeImage {
width: 100%;
}


.label {
-fx-font-size: 11pt;
-fx-font-family: "Segoe UI Semibold";
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/view/EmailButton.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Button?>


<Button fx:id="emailButton" mnemonicParsing="false" onAction="#handleEmailButtonPressed" text="Email" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" />
66 changes: 47 additions & 19 deletions src/main/resources/view/MainWindow.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,59 @@
<?import javafx.scene.control.MenuBar?>
<?import javafx.scene.control.MenuItem?>
<?import javafx.scene.control.SplitPane?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.StackPane?>
<?import javafx.scene.layout.VBox?>

<VBox fx:id="vBox" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1">
<stylesheets>
<URL value="@DarkTheme.css"/>
<URL value="@Extensions.css"/>
</stylesheets>
<VBox xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1">
<stylesheets>
<URL value="@DarkTheme.css" />
<URL value="@Extensions.css" />
</stylesheets>

<MenuBar fx:id="menuBar" VBox.vgrow="NEVER">
<Menu mnemonicParsing="false" text="File">
<MenuItem mnemonicParsing="false" onAction="#handleBlackTheme" text="Black Theme"/>
<MenuBar fx:id="menuBar" VBox.vgrow="NEVER">
<Menu mnemonicParsing="false" text="File">
<MenuItem mnemonicParsing="false" onAction="#handleBlackTheme" text="Black Theme"/>
<MenuItem mnemonicParsing="false" onAction="#handleWhiteTheme" text="White Theme"/>
<MenuItem mnemonicParsing="false" onAction="#handleGreenTheme" text="Green Theme"/>
<MenuItem mnemonicParsing="false" onAction="#handleExit" text="Exit"/>
</Menu>
<Menu mnemonicParsing="false" text="Help">
<MenuItem fx:id="helpMenuItem" mnemonicParsing="false" onAction="#handleHelp" text="Help"/>
</Menu>
</MenuBar>

<StackPane fx:id="commandBoxPlaceholder" styleClass="pane-with-border" VBox.vgrow="NEVER">
<padding>
<Insets bottom="5" left="10" right="10" top="5"/>
</padding>
<MenuItem mnemonicParsing="false" onAction="#handleExit" text="Exit" />
</Menu>
<Menu mnemonicParsing="false" text="Help">
<MenuItem fx:id="helpMenuItem" mnemonicParsing="false" onAction="#handleHelp" text="Help" />
</Menu>
</MenuBar>

<StackPane fx:id="commandBoxPlaceholder" styleClass="pane-with-border" VBox.vgrow="NEVER">
<padding>
<Insets bottom="5" left="10" right="10" top="5" />
</padding>
</StackPane>

<StackPane fx:id="resultDisplayPlaceholder" maxHeight="100" minHeight="100" prefHeight="100" styleClass="pane-with-border" VBox.vgrow="NEVER">
<padding>
<Insets bottom="5" left="10" right="10" top="5" />
</padding>
</StackPane>

<SplitPane id="splitPane" fx:id="splitPane" dividerPositions="0.4352226720647773, 0.569838056680162" VBox.vgrow="ALWAYS">
<VBox fx:id="personList" minWidth="340" prefWidth="340.0" SplitPane.resizableWithParent="false">
<padding>
<Insets bottom="10" left="10" right="10" top="10" />
</padding>
<StackPane fx:id="personListPanelPlaceholder" VBox.vgrow="ALWAYS" />
<HBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="100.0" prefWidth="323.0">
<children>
<StackPane fx:id="deleteButtonPlaceholder" alignment="TOP_CENTER" prefHeight="100.0" prefWidth="168.0" />
<StackPane fx:id="emailButtonPlaceholder" alignment="TOP_CENTER" prefHeight="100.0" prefWidth="167.0" />
</children>
</HBox>
</VBox>
<VBox prefHeight="667.0" prefWidth="113.0" />

<StackPane fx:id="browserPlaceholder" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="667.0" prefWidth="593.0">
<padding>
<Insets bottom="10" left="10" right="10" top="10" />
</padding>
</StackPane>

<StackPane fx:id="resultDisplayPlaceholder" maxHeight="100" minHeight="100" prefHeight="100"
Expand Down
Loading

0 comments on commit 049b207

Please sign in to comment.