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

aaa53, cl305 #32

Open
wants to merge 1 commit 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>
28 changes: 28 additions & 0 deletions src/BrowserException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

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
}

}
13 changes: 7 additions & 6 deletions src/BrowserModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,29 @@ 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");
}

/**
* Changes current page to given URL, removing next history.
*/
public URL go (String url) {
public URL go (String url) throws BrowserException {
try {
URL tmp = completeURL(url);
// unfortunately, completeURL may not have returned a valid URL, so test it
Expand All @@ -76,7 +76,7 @@ public URL go (String url) {
return myCurrentURL;
}
catch (Exception e) {
return null;
throw new BrowserException("no URL");
}
}

Expand All @@ -96,6 +96,7 @@ public boolean hasPrevious () {

/**
* Returns URL of the current home page or null if none is set.
* @throws BrowserException
*/
public URL getHome () {
return myHome;
Expand Down
40 changes: 29 additions & 11 deletions src/BrowserView.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public class BrowserView {
private Button myBackButton;
private Button myNextButton;
private Button myHomeButton;
private Button setFavoriteButton;
private Button myFavoriteGoButton;
// favorites
private ComboBox<String> myFavorites;
// get strings from resource file
Expand All @@ -84,19 +86,19 @@ 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());
}
}

Expand Down Expand Up @@ -126,12 +128,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){
showError(e.getMessage());
}
}

// move to the previous URL in the history
private void back () {
update(myModel.back());
try{
update(myModel.back());
}
catch(BrowserException e){
showError(e.getMessage());
}
}

// change current URL to the home page, if set
Expand All @@ -143,7 +155,7 @@ private void home () {
private void showFavorite (String favorite) {
showPage(myModel.getFavorite(favorite).toString());
// reset favorites ComboBox so the same choice can be made again
myFavorites.setValue(null);
//myFavorites.setValue(null);
}

// update just the view to display given URL
Expand Down Expand Up @@ -185,7 +197,7 @@ private Node makePageDisplay () {
// organize user's options for controlling/giving input to model
private Node makeInputPanel () {
VBox result = new VBox();
result.getChildren().addAll(makeNavigationPanel(), makePreferencesPanel());
result.getChildren().addAll(makePreferencesPanel(), makeNavigationPanel());
return result;
}

Expand Down Expand Up @@ -230,6 +242,12 @@ private Node makePreferencesPanel () {
myModel.setHome();
enableButtons();
}));
setFavoriteButton = makeButton("AddFavoriteCommand", event -> addFavorite());
result.getChildren().add(setFavoriteButton);
result.getChildren().add(myFavorites);
myFavoriteGoButton = makeButton("GoCommand", event -> showFavorite(myFavorites.getValue()));
result.getChildren().add(myFavoriteGoButton);
myFavorites.setValue("My Favorites");
return result;
}

Expand Down
8 changes: 4 additions & 4 deletions src/resources/default.css
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
.root {
-fx-font-size: 14pt;
-fx-font-family: "Courier New";
-fx-font-family: "Times New Roman";
-fx-base: rgb(132, 145, 47);
-fx-background: rgb(225, 228, 203);
}

.button {
-fx-text-fill: #006464;
-fx-background-color: #DFB951;
-fx-background-color: #9933CC;
-fx-border-radius: 20;
-fx-background-radius: 20;
-fx-padding: 8;
Expand All @@ -29,12 +29,12 @@

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

.text-field {
-fx-font-size: 14pt;
-fx-font-family: "Segoe UI Semibold";
-fx-font-family: "Comic Sans";
}