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

Eric Jiang (elj16) & Kelly Cochran (kjc37) #22

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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# lab_browser
A simple GUI example: a web browser

Kelly Cochran
Eric Jiang
15 changes: 15 additions & 0 deletions src/BrowserException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

public class BrowserException extends RuntimeException {
/**
*
*/
private static final long serialVersionUID = 1L;

public BrowserException() {
super();
}

public BrowserException(String message) {
super(message);
}
}
40 changes: 33 additions & 7 deletions src/BrowserView.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.text.Text;
import javafx.scene.web.WebView;
import javax.imageio.ImageIO;
import org.w3c.dom.Document;
Expand Down Expand Up @@ -75,6 +76,9 @@ public BrowserView (BrowserModel model, String language) {
myModel = model;
// use resources for labels
myResources = ResourceBundle.getBundle(DEFAULT_RESOURCE_PACKAGE + language);
myFavorites = new ComboBox<String>();
myFavorites.setOnAction(event -> showFavorite(myFavorites.getValue()));
myFavorites.setValue("Favorites");
BorderPane root = new BorderPane();
// must be first since other panels may refer to page
root.setCenter(makePageDisplay());
Expand All @@ -84,19 +88,26 @@ 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 (url != null) {

/*if (url != null) {
update(valid);
}
else {
showError("Could not load " + url);
}*/
try {
URL valid = myModel.go(url);
update(valid);
} catch (BrowserException ex) {
showError(ex.getMessage());
ex.printStackTrace();
}
}

Expand All @@ -120,18 +131,28 @@ public void showStatus (String message) {
public void showError (String message) {
Alert alert = new Alert(AlertType.ERROR);
alert.setTitle(myResources.getString("ErrorTitle"));
alert.setContentText(message);
alert.setContentText(String.format(myResources.getString("ErrorMessage"), message));
alert.showAndWait();
}

// 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 @@ -145,7 +166,7 @@ private void showFavorite (String favorite) {
}

// update just the view to display given URL
private void update (URL url) {
private void update (URL url) throws BrowserException {
myPage.getEngine().load(url.toString());
myURLDisplay.setText(url.toString());
enableButtons();
Expand Down Expand Up @@ -225,6 +246,11 @@ private Node makePreferencesPanel () {
myModel.setHome();
enableButtons();
}));
result.getChildren().add(makeButton("AddFavoriteCommand", event -> {
addFavorite();
enableButtons();
}));
result.getChildren().add(myFavorites);
return result;
}

Expand Down
1 change: 1 addition & 0 deletions src/resources/English.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ ErrorTitle=Browser Error
FavoritePromptTitle=Add Favorite
FavoriteFirstItem=All Favorites
SetHomeCommand=Set Home
ErrorMessage=Could not load %s check your spleeing
14 changes: 10 additions & 4 deletions src/resources/default.css
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
H3 {
-fx-font-family: "Comic Sans MS";
}

.root {
-fx-font-size: 14pt;
-fx-font-family: "Courier New";
-fx-font-family: "Comic Sans MS";
-fx-base: rgb(132, 145, 47);
-fx-background: rgb(225, 228, 203);
}

.button {
-fx-text-fill: #006464;
-fx-font-family: "Comic Sans MS";
-fx-text-fill: #000000;
-fx-background-color: #DFB951;
-fx-border-radius: 20;
-fx-background-radius: 20;
Expand All @@ -18,6 +23,7 @@
}

.combo-box-base {
-fx-font-family: "Comic Sans MS";
-fx-text-base-color: #006464;
-fx-background-color: #DFB951;
-fx-border-radius: 20;
Expand All @@ -29,12 +35,12 @@

.label {
-fx-font-size: 11pt;
-fx-font-family: "Segoe UI Semibold";
-fx-font-family: "Comic Sans MS";
-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 MS";
}