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

Modifications on Lab from class- cgu4 & cds33 #21

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

Names: Connor Usry (cgu4) and Chris Streiffer (cds33)
14 changes: 14 additions & 0 deletions src/BrowserException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public class BrowserException extends RuntimeException{
/**
*
*/
private static final long serialVersionUID = 1L;

public BrowserException() {}

//Constructor that accepts a message
public BrowserException(String message)
{
super(message);
}
}
17 changes: 11 additions & 6 deletions src/BrowserModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;


/**
Expand All @@ -15,6 +16,8 @@
public class BrowserModel {
// constants
public static final String PROTOCOL_PREFIX = "http://";
public static final String DEFAULT_RESOURCE_PACKAGE = "resources/";
private ResourceBundle myErrors;
// state
private URL myHome;
private URL myCurrentURL;
Expand All @@ -26,7 +29,8 @@ public class BrowserModel {
/**
* Creates an empty model.
*/
public BrowserModel () {
public BrowserModel (String s) {
myErrors = ResourceBundle.getBundle(DEFAULT_RESOURCE_PACKAGE + s);
myHome = null;
myCurrentURL = null;
myCurrentIndex = -1;
Expand Down Expand Up @@ -115,11 +119,12 @@ public void addFavorite (String name) {
/**
* Returns URL from favorites associated with given name, null if none set.
*/
public URL getFavorite (String name) {
if (name != null && !name.equals("") && myFavorites.containsKey(name)) {
return myFavorites.get(name);
}
return null;
public URL getFavorite (String name) throws BrowserException {
if( name != null && !name.equals("") && myFavorites.containsKey(name)) {
return myFavorites.get(name);
} else {
throw new BrowserException(myErrors.getString("BrowserException"));
}
}

// deal with a potentially incomplete URL
Expand Down
25 changes: 23 additions & 2 deletions src/BrowserView.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.w3c.dom.events.EventTarget;



/**
* A class used to display the viewer for a simple HTML browser.
*
Expand Down Expand Up @@ -65,6 +66,7 @@ public class BrowserView {
private ComboBox<String> myFavorites;
// get strings from resource file
private ResourceBundle myResources;

// the data
private BrowserModel myModel;

Expand All @@ -75,16 +77,20 @@ public BrowserView (BrowserModel model, String language) {
myModel = model;
// use resources for labels
myResources = ResourceBundle.getBundle(DEFAULT_RESOURCE_PACKAGE + language);

myFavorites = new ComboBox<String>();
BorderPane root = new BorderPane();
// must be first since other panels may refer to page
root.setCenter(makePageDisplay());
root.setTop(makeInputPanel());
root.setBottom(makeInformationPanel());
// control the navigation
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);
}

/**
Expand Down Expand Up @@ -141,7 +147,12 @@ private void home () {

// change page to favorite choice
private void showFavorite (String favorite) {
showPage(myModel.getFavorite(favorite).toString());
try {
showPage(myModel.getFavorite(favorite).toString());
} catch (BrowserException e) {
throw e;
}

}

// update just the view to display given URL
Expand Down Expand Up @@ -225,6 +236,16 @@ private Node makePreferencesPanel () {
myModel.setHome();
enableButtons();
}));
result.getChildren().add(makeButton("SetFavoriteCommand", event -> {
addFavorite();
}));
result.getChildren().add(myFavorites);
myFavorites.valueProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue ov, String t, String t1){
showFavorite(t1);
}
});
return result;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class Main extends Application {
@Override
public void start (Stage stage) {
// create program specific components
BrowserModel model = new BrowserModel();
BrowserModel model = new BrowserModel("Errors");
BrowserView display = new BrowserView(model, "English");
// give the window a title
stage.setTitle(TITLE);
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
SetFavoriteCommand=Set Favorite
1 change: 1 addition & 0 deletions src/resources/Errors.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BrowserException="You Messed Up"