Skip to content
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>
39 changes: 39 additions & 0 deletions src/BrowserException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

public class BrowserException extends RuntimeException {

String eMessage;

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

public BrowserException(String message) {
super(message);
this.eMessage = 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);
this.eMessage = message;
// 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
this.eMessage = message;
}

public String getMessage(){
return eMessage;

}

}
28 changes: 22 additions & 6 deletions src/BrowserModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import java.util.ResourceBundle;
import java.util.Set;

/**
* This represents the heart of the browser: the collections
Expand All @@ -15,12 +16,15 @@
public class BrowserModel {
// constants
public static final String PROTOCOL_PREFIX = "http://";
public static final String DEFAULT_ERROR_PACKAGE = "resources/ModelErrors";
// state
private URL myHome;
private URL myCurrentURL;
private int myCurrentIndex;
private List<URL> myHistory;
private Map<String, URL> myFavorites;
// get strings from resource file
private ResourceBundle myResources;


/**
Expand All @@ -32,6 +36,7 @@ public BrowserModel () {
myCurrentIndex = -1;
myHistory = new ArrayList<>();
myFavorites = new HashMap<>();
myResources = ResourceBundle.getBundle(DEFAULT_ERROR_PACKAGE);
}

/**
Expand All @@ -42,7 +47,9 @@ public URL next () {
myCurrentIndex++;
return myHistory.get(myCurrentIndex);
}
return null;
else{
throw new BrowserException(myResources.getString("NextError"));
}
}

/**
Expand All @@ -53,7 +60,9 @@ public URL back () {
myCurrentIndex--;
return myHistory.get(myCurrentIndex);
}
return null;
else{
throw new BrowserException(myResources.getString("BackError"));
}
}

/**
Expand All @@ -76,7 +85,7 @@ public URL go (String url) {
return myCurrentURL;
}
catch (Exception e) {
return null;
throw new BrowserException(String.format(myResources.getString("ErrorOnGo"), url));
}
}

Expand Down Expand Up @@ -120,6 +129,10 @@ public void addFavorite (String name) {
myFavorites.put(name, myCurrentURL);
}
}

public Set<String> getFavoriteList(){
return myFavorites.keySet();
}

/**
* Returns URL from favorites associated with given name, null if none set.
Expand All @@ -128,7 +141,9 @@ public URL getFavorite (String name) {
if (name != null && !name.equals("") && myFavorites.containsKey(name)) {
return myFavorites.get(name);
}
return null;
else{
throw new BrowserException();
}
}

// deal with a potentially incomplete URL
Expand All @@ -146,9 +161,10 @@ 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(String.format(myResources.getString("BadURL"), possible));
}
}
}
}

}
56 changes: 46 additions & 10 deletions src/BrowserView.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import java.awt.Dimension;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.Optional;
import java.util.ResourceBundle;
Expand Down Expand Up @@ -47,6 +49,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 GOOGLE_FONT = "https://fonts.googleapis.com/css?family=Permanent+Marker";
public static final String STYLESHEET = "default.css";
public static final String BLANK = " ";

Expand All @@ -61,6 +64,7 @@ public class BrowserView {
private Button myBackButton;
private Button myNextButton;
private Button myHomeButton;
private Button myAddFavoriteButton;
// favorites
private ComboBox<String> myFavorites;
// get strings from resource file
Expand All @@ -84,19 +88,20 @@ 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);
myScene.getStylesheets().add(GOOGLE_FONT);
}

/**
* 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 @@ -224,16 +229,33 @@ public void handle (ActionEvent event) {
// make buttons for setting favorites/home URLs
private Node makePreferencesPanel () {
HBox result = new HBox();
myFavorites = new ComboBox<String>();
myFavorites = makeFavoritesBox();
// ADD REST OF CODE HERE
result.getChildren().add(makeButton("SetHomeCommand", event -> {
myModel.setHome();
enableButtons();
}));
myAddFavoriteButton = makeButton("AddFavoriteCommand", event -> addFavorite());
result.getChildren().add(myAddFavoriteButton);
result.getChildren().add(myFavorites);
return result;
}

private ComboBox<String> makeFavoritesBox(){
ComboBox<String> box = new ComboBox<String>();
for(String fave: myModel.getFavoriteList()){
box.getItems().add(fave);
}
box.setOnAction(event -> selectFavorite(event));
return box;
}

private void selectFavorite(ActionEvent event) {
String faveName = myFavorites.getValue();;
showFavorite(faveName);
}

// makes a button using either an image or a label
// makes a button using either an image or a label
private Button makeButton (String property, EventHandler<ActionEvent> handler) {
// represent all supported image suffixes
final String IMAGEFILE_SUFFIXES =
Expand All @@ -247,7 +269,21 @@ private Button makeButton (String property, EventHandler<ActionEvent> handler) {
} else {
result.setText(label);
}
result.setOnAction(handler);
result.setOnAction(ex -> {
try{
Method method = null;
try {
method = this.getClass().getMethod("addFavorite");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
method.invoke(this);
}catch (IllegalArgumentException e) {
} catch (IllegalAccessException e) {
} catch (InvocationTargetException e) {
}
});
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
ErrorOnGo=Could not load %s
1 change: 1 addition & 0 deletions src/resources/Gibberish.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ ErrorTitle=BAD
FavoritePromptTitle=123456789
FavoriteFirstItem=Go Away
SetHomeCommand=ET Phone Home
ErrorOnGo=asldkjfkdjfijwiejf %s
1 change: 1 addition & 0 deletions src/resources/Image.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ FavoritePrompt=Enter name
FavoritePromptTitle=Add Favorite
FavoriteFirstItem=All Favorites
SetHomeCommand=Set Home
ErrorOnGo=Could not load %s
5 changes: 5 additions & 0 deletions src/resources/ModelErrors.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ErrorOnGo=Could not load %s today!
BackError=No Previous Page!
FavoritError=No Favorites!
NextError=No Next Page!
BadURL=Could not find %s
41 changes: 21 additions & 20 deletions src/resources/default.css
Original file line number Diff line number Diff line change
@@ -1,40 +1,41 @@
.root {
-fx-font-size: 14pt;
-fx-font-family: "Courier New";
-fx-base: rgb(132, 145, 47);
-fx-background: rgb(225, 228, 203);
-fx-font-size: 12pt;
-fx-font-family: "Permanent Marker";
-fx-base: #0736A4;
-fx-background: #D32323;
-fx-text-fill:black;
}

.button {
-fx-text-fill: #006464;
-fx-background-color: #DFB951;
-fx-border-radius: 20;
-fx-background-radius: 20;
-fx-padding: 8;
-fx-background-color:white;
-fx-padding: 6;
-fx-border-color: #0736A4;
-fx-border-radius: 2;
-fx-text-fill:black;
}

.button:hover {
-fx-background-color: #3a3a3a;
.button:hover,
.button:focus {
-fx-background-color: #0736A4;;
-fx-text-fill: white;
}

.combo-box-base {
-fx-text-base-color: #006464;
-fx-background-color: #DFB951;
-fx-border-radius: 20;
-fx-background-radius: 20;
-fx-background-color:white;
}
.combo-box-base:hover {
-fx-background-color: #3a3a3a;
-fx-background-color: #0736A4;;
-fx-text-fill: white;
}

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

.text-field {
-fx-font-size: 14pt;
-fx-font-family: "Segoe UI Semibold";
-fx-font-size: 12pt;
-fx-font-family: "Permanent Marker";
}