Skip to content

browser #25

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

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

wj43: Wanning Jiang

cw272: Cheng Wei
5 changes: 5 additions & 0 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.Set;


/**
Expand Down Expand Up @@ -121,6 +122,10 @@ public URL getFavorite (String name) {
}
return null;
}

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

// deal with a potentially incomplete URL
private URL completeURL (String possible) {
Expand Down
30 changes: 28 additions & 2 deletions src/BrowserView.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import java.awt.Dimension;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.ResourceBundle;
import javafx.beans.value.ChangeListener;
Expand Down Expand Up @@ -61,12 +63,15 @@ 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
private ResourceBundle myResources;
// the data
private BrowserModel myModel;



/**
* Create a view of the given model of a web browser.
Expand All @@ -84,7 +89,7 @@ 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);
}

/**
Expand All @@ -96,7 +101,8 @@ public void showPage (String url) {
update(valid);
}
else {
showError("Could not load " + url);
// showError("Could not load " + url);
showError(String.format("Could not load %s check your spleeing", url));
}
}

Expand Down Expand Up @@ -210,11 +216,13 @@ public void handle (ActionEvent event) {
result.getChildren().add(myNextButton);
myHomeButton = makeButton("HomeCommand", event -> home());
result.getChildren().add(myHomeButton);

// if user presses button or enter in text field, load/show the URL
EventHandler<ActionEvent> showHandler = new ShowPage();
result.getChildren().add(makeButton("GoCommand", showHandler));
myURLDisplay = makeInputField(40, showHandler);
result.getChildren().add(myURLDisplay);

return result;
}

Expand All @@ -225,9 +233,27 @@ private Node makePreferencesPanel () {
myModel.setHome();
enableButtons();
}));
myAddFavoriteButton = makeButton("AddFavoriteCommand", event -> addFavorite());
result.getChildren().add(myAddFavoriteButton);
myFavorites = makeComboBox("FavoritesList", event -> showFavorite());
result.getChildren().add(myFavorites);
return result;
}

public void showFavorite()
{
String string = myFavorites.getValue();
showPage(myModel.getFavorite(string).toString());
}

private ComboBox<String> makeComboBox (String property, EventHandler<ActionEvent> handler) {
ComboBox<String> result = new ComboBox<String>();
result.getItems().addAll(myModel.getFavoriteList());
result.setOnAction(handler);
result.setPromptText("Favorite Sites");
return result;
}

// makes a button using either an image or a label
private Button makeButton (String property, EventHandler<ActionEvent> handler) {
// represent all supported image suffixes
Expand Down