diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..fb50116
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,6 @@
+
+
+
+
+
+
diff --git a/src/BrowserException.java b/src/BrowserException.java
new file mode 100644
index 0000000..4f4ea0c
--- /dev/null
+++ b/src/BrowserException.java
@@ -0,0 +1,20 @@
+
+public class BrowserException extends RuntimeException{
+ private static final long serialVersionUID = 1997753363232807009L;
+
+ public BrowserException(){
+
+ }
+ public BrowserException(String message){
+ super(message);
+ }
+ public BrowserException(Throwable cause){
+ super(cause);
+ }
+ public BrowserException(String message, Throwable cause){
+ super(message,cause);
+ }
+ public BrowserException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace){
+ super(message,cause,enableSuppression,writableStackTrace);
+ }
+}
diff --git a/src/BrowserModel.java b/src/BrowserModel.java
index 9263bb3..cfb9932 100755
--- a/src/BrowserModel.java
+++ b/src/BrowserModel.java
@@ -4,6 +4,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.ResourceBundle;
/**
@@ -21,13 +22,15 @@ public class BrowserModel {
private int myCurrentIndex;
private List myHistory;
private Map myFavorites;
+ private ResourceBundle myResources;
/**
* Creates an empty model.
*/
- public BrowserModel () {
+ public BrowserModel (String language) {
myHome = null;
+ myResources = ResourceBundle.getBundle(BrowserView.DEFAULT_RESOURCE_PACKAGE + language+"Error");
myCurrentURL = null;
myCurrentIndex = -1;
myHistory = new ArrayList<>();
@@ -58,8 +61,9 @@ public URL back () {
/**
* Changes current page to given URL, removing next history.
+ * @throws BrowserException
*/
- 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
@@ -76,7 +80,7 @@ public URL go (String url) {
return myCurrentURL;
}
catch (Exception e) {
- return null;
+ throw new BrowserException(String.format(myResources.getString("ErrorLoad"),url));
}
}
diff --git a/src/BrowserView.java b/src/BrowserView.java
index f9d591d..487d8ac 100644
--- a/src/BrowserView.java
+++ b/src/BrowserView.java
@@ -1,4 +1,5 @@
import java.awt.Dimension;
+import java.lang.reflect.Method;
import java.net.URL;
import java.util.Optional;
import java.util.ResourceBundle;
@@ -47,7 +48,7 @@ public class BrowserView {
// constants
public static final Dimension DEFAULT_SIZE = new Dimension(800, 600);
public static final String DEFAULT_RESOURCE_PACKAGE = "resources/";
- public static final String STYLESHEET = "default.css";
+ public static final String STYLESHEET = "custom.css";
public static final String BLANK = " ";
// scene, needed to report back to Application
@@ -61,6 +62,7 @@ public class BrowserView {
private Button myBackButton;
private Button myNextButton;
private Button myHomeButton;
+ private Button myFavButton;
// favorites
private ComboBox myFavorites;
// get strings from resource file
@@ -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) {
+ try{
+ URL valid = myModel.go(url);
update(valid);
}
- else {
- showError("Could not load " + url);
+ catch(BrowserException e){
+ showError(e.getMessage());
}
}
@@ -143,7 +145,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
@@ -213,6 +215,8 @@ public void handle (ActionEvent event) {
result.getChildren().add(myNextButton);
myHomeButton = makeButton("HomeCommand", event -> home());
result.getChildren().add(myHomeButton);
+ myFavButton = makeButton("AddFavoriteCommand",event-> addFavorite());
+ result.getChildren().add(myFavButton);
// if user presses button or enter in text field, load/show the URL
EventHandler showHandler = new ShowPage();
result.getChildren().add(makeButton("GoCommand", showHandler));
@@ -226,6 +230,8 @@ private Node makePreferencesPanel () {
HBox result = new HBox();
myFavorites = new ComboBox();
// ADD REST OF CODE HERE
+ result.getChildren().add(myFavorites);
+ myFavorites.setOnAction(event->showFavorite(myFavorites.getValue()));
result.getChildren().add(makeButton("SetHomeCommand", event -> {
myModel.setHome();
enableButtons();
@@ -234,7 +240,7 @@ private Node makePreferencesPanel () {
}
// makes a button using either an image or a label
- private Button makeButton (String property, EventHandler handler) {
+ private Button makeButton (String property, String handler) {
// represent all supported image suffixes
final String IMAGEFILE_SUFFIXES =
String.format(".*\\.(%s)", String.join("|", ImageIO.getReaderFileSuffixes()));
@@ -247,7 +253,9 @@ private Button makeButton (String property, EventHandler handler) {
} else {
result.setText(label);
}
- result.setOnAction(handler);
+// result.setOnAction(handler);
+ Method m = this.getClass().getDeclaredMethod(handler);
+ result.setOnAction(e->m.invoke());
return result;
}
diff --git a/src/Main.java b/src/Main.java
index c258d02..60b2152 100755
--- a/src/Main.java
+++ b/src/Main.java
@@ -11,13 +11,14 @@ public class Main extends Application {
// convenience constants
public static final String TITLE = "NanoBrowser";
public static final String DEFAULT_START_PAGE = "http://www.cs.duke.edu/rcd";
+ public static final String LANGUAGE = "English";
@Override
public void start (Stage stage) {
// create program specific components
- BrowserModel model = new BrowserModel();
- BrowserView display = new BrowserView(model, "English");
+ BrowserModel model = new BrowserModel(LANGUAGE);
+ BrowserView display = new BrowserView(model, LANGUAGE);
// give the window a title
stage.setTitle(TITLE);
// add our user interface components to Frame and show it
diff --git a/src/resources/English.properties b/src/resources/English.properties
index 5cb3530..0c19314 100755
--- a/src/resources/English.properties
+++ b/src/resources/English.properties
@@ -5,6 +5,7 @@ GoCommand=Go
AddFavoriteCommand=Add Favorites
FavoritePrompt=Enter name
ErrorTitle=Browser Error
+ErrorLoad=Could not load %s today
FavoritePromptTitle=Add Favorite
FavoriteFirstItem=All Favorites
SetHomeCommand=Set Home
diff --git a/src/resources/EnglishError.properties b/src/resources/EnglishError.properties
new file mode 100644
index 0000000..e76b1f0
--- /dev/null
+++ b/src/resources/EnglishError.properties
@@ -0,0 +1,2 @@
+ErrorTitle=Browser Error
+ErrorLoad=Could not load %s today
diff --git a/src/resources/custom.css b/src/resources/custom.css
new file mode 100644
index 0000000..69d286d
--- /dev/null
+++ b/src/resources/custom.css
@@ -0,0 +1,40 @@
+.root {
+ -fx-font-size: 14pt;
+ -fx-font-family: "Courier New";
+ -fx-base: red;
+ -fx-background: skyblue;
+}
+
+.button {
+ -fx-text-fill: #006464;
+ -fx-background-color: lightgreen;
+ -fx-border-radius: 20;
+ -fx-background-radius: 20;
+ -fx-padding: 8;
+}
+
+.button:hover {
+ -fx-background-color: #3a3a3a;
+}
+
+.combo-box-base {
+ -fx-text-base-color: #006464;
+ -fx-background-color: orange;
+ -fx-border-radius: 20;
+ -fx-background-radius: 20;
+}
+.combo-box-base:hover {
+ -fx-background-color: #3a3a3a;
+}
+
+.label {
+ -fx-font-size: 11pt;
+ -fx-font-family: "Segoe UI Semibold";
+ -fx-text-fill: #006464;
+ -fx-opacity: 0.6;
+}
+
+.text-field {
+ -fx-font-size: 14pt;
+ -fx-font-family: "Segoe UI Semibold";
+}