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

mmc56 tln11 #44

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Next Next commit
mmc56
michellexchen committed Feb 4, 2016

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit e2b470297a8f49b91f7d8d39b6123f2355dc9fbc
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>
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 RuntimeException {

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
}

}
10 changes: 5 additions & 5 deletions src/BrowserModel.java
Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@ public URL next () {
myCurrentIndex++;
return myHistory.get(myCurrentIndex);
}
return null;
throw new BrowserException();
}

/**
@@ -53,7 +53,7 @@ public URL back () {
myCurrentIndex--;
return myHistory.get(myCurrentIndex);
}
return null;
throw new BrowserException();
}

/**
@@ -76,7 +76,7 @@ public URL go (String url) {
return myCurrentURL;
}
catch (Exception e) {
return null;
throw new BrowserException(url);
}
}

@@ -128,7 +128,7 @@ public URL getFavorite (String name) {
if (name != null && !name.equals("") && myFavorites.containsKey(name)) {
return myFavorites.get(name);
}
return null;
throw new BrowserException(name);
}

// deal with a potentially incomplete URL
@@ -146,7 +146,7 @@ private URL completeURL (String possible) {
// e.g., let user leave off initial protocol
return new URL(PROTOCOL_PREFIX + possible);
} catch (MalformedURLException eee) {
return null;
throw new BrowserException(possible);
}
}
}
30 changes: 22 additions & 8 deletions src/BrowserView.java
Original file line number Diff line number Diff line change
@@ -61,6 +61,7 @@ public class BrowserView {
private Button myBackButton;
private Button myNextButton;
private Button myHomeButton;
private Button myFavoritesButton;
// favorites
private ComboBox<String> myFavorites;
// get strings from resource file
@@ -84,19 +85,18 @@ public BrowserView (BrowserModel model, String language) {
enableButtons();
// create scene to hold UI
myScene = new Scene(root, DEFAULT_SIZE.width, DEFAULT_SIZE.height);
//myScene.getStylesheets().add(DEFAULT_RESOURCE_PACKAGE + STYLESHEET);
myScene.getStylesheets().add(DEFAULT_RESOURCE_PACKAGE + STYLESHEET);
}

/**
* Display given URL.
*/
public void showPage (String url) {
URL valid = myModel.go(url);
if (valid != null) {
update(valid);
}
else {
showError("Could not load " + url);
try {
URL valid = myModel.go(url);
update(valid);
} catch (BrowserException e) {
showError(e.getMessage());
}
}

@@ -141,7 +141,8 @@ private void home () {

// change page to favorite choice
private void showFavorite (String favorite) {
showPage(myModel.getFavorite(favorite).toString());
String url = myModel.getFavorite(favorite).toString();
showPage(url);
// reset favorites ComboBox so the same choice can be made again
myFavorites.setValue(null);
}
@@ -230,6 +231,19 @@ private Node makePreferencesPanel () {
myModel.setHome();
enableButtons();
}));

myFavoritesButton = makeButton("AddFavoriteCommand", event -> {
addFavorite();
enableButtons();
});
result.getChildren().add(myFavoritesButton);
result.getChildren().add(myFavorites);

myFavorites.setOnAction((event) -> {
String selectedPerson = myFavorites.getSelectionModel().getSelectedItem();
showFavorite(selectedPerson);
});

return result;
}

1 change: 1 addition & 0 deletions src/resources/English.properties
Original file line number Diff line number Diff line change
@@ -8,3 +8,4 @@ ErrorTitle=Browser Error
FavoritePromptTitle=Add Favorite
FavoriteFirstItem=All Favorites
SetHomeCommand=Set Home
ErrorMessage = Could not load