Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Daniel McKee (dbm33), Tina Liang (tl150) #29

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="bin"/>
</classpath>
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# lab_browser
A simple GUI example: a web browser
Daniel McKee (dbm33) and Tina Liang (tl150)
29 changes: 29 additions & 0 deletions src/BrowserException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

public class BrowserException extends Exception {

public BrowserException() {
// TODO Auto-generated constructor stub
}

public BrowserException(String message) {
super(message);
// TODO Auto-generated constructor stub
}

public BrowserException(Throwable cause) {
super(cause);
// TODO Auto-generated constructor stub
}

public BrowserException(String message, Throwable cause) {
super(message, cause);
// TODO Auto-generated constructor stub
}

public BrowserException(String message, Throwable cause,
boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
// TODO Auto-generated constructor stub
}

}
16 changes: 10 additions & 6 deletions src/BrowserModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,23 @@ public BrowserModel () {
/**
* Returns the first page in next history, null if next history is empty.
*/
public URL next () {
public URL next () throws BrowserException{
if (hasNext()) {
myCurrentIndex++;
return myHistory.get(myCurrentIndex);
}
return null;
throw new BrowserException("No next page. ");
}

/**
* Returns the first page in back history, null if back history is empty.
*/
public URL back () {
public URL back () throws BrowserException{
if (hasPrevious()) {
myCurrentIndex--;
return myHistory.get(myCurrentIndex);
}
return null;
throw new BrowserException("No previous page. ");
}

/**
Expand Down Expand Up @@ -114,12 +114,14 @@ public void addFavorite (String name) {

/**
* Returns URL from favorites associated with given name, null if none set.
* @throws BrowserException
*/
public URL getFavorite (String name) {
public URL getFavorite (String name) throws BrowserException {
if (name != null && !name.equals("") && myFavorites.containsKey(name)) {
return myFavorites.get(name);
}
return null;
// return null;
throw new BrowserException("No favorites set.");
}

// deal with a potentially incomplete URL
Expand All @@ -142,4 +144,6 @@ private URL completeURL (String possible) {
}
}
}


}
39 changes: 36 additions & 3 deletions src/BrowserView.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import java.net.URL;
import java.util.Optional;
import java.util.ResourceBundle;

import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.concurrent.Worker;
Expand All @@ -23,7 +24,9 @@
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.web.WebView;

import javax.imageio.ImageIO;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
Expand Down Expand Up @@ -126,12 +129,22 @@ public void showError (String message) {

// move to the next URL in the history
private void next () {
update(myModel.next());
try {
update(myModel.next());
} catch (BrowserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

// move to the previous URL in the history
private void back () {
update(myModel.back());
try {
update(myModel.back());
} catch (BrowserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

// change current URL to the home page, if set
Expand All @@ -141,7 +154,12 @@ private void home () {

// change page to favorite choice
private void showFavorite (String favorite) {
showPage(myModel.getFavorite(favorite).toString());
try {
showPage(myModel.getFavorite(favorite).toString());
} catch (BrowserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

// update just the view to display given URL
Expand Down Expand Up @@ -225,6 +243,21 @@ private Node makePreferencesPanel () {
myModel.setHome();
enableButtons();
}));
result.getChildren().add(makeButton("AddFavoriteCommand", event -> {
// TextInputDialog info = new TextInputDialog();
// info.showAndWait();
// String name = info.getResult();
addFavorite();

enableButtons();
}));
myFavorites = new ComboBox<String>();
myFavorites.setOnAction(event -> {

showFavorite(myFavorites.getValue());
});
result.getChildren().add(myFavorites);

return result;
}

Expand Down