Skip to content

Ankit Kayastha (ak308), Jiadong Yin (jy114) Lab Browser #24

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 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
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>
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

Names: Ankit Kayastha (ak308), Jiadong Yin (jy114)

6 changes: 6 additions & 0 deletions src/BrowserException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

public class BrowserException extends Exception {
public BrowserException (String string) {
super(string);
}
}
19 changes: 10 additions & 9 deletions src/BrowserModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,30 +36,31 @@ public BrowserModel () {

/**
* Returns the first page in next history, null if next history is empty.
* @throws BrowserException
*/
public URL next () {
public URL next () throws BrowserException {
if (hasNext()) {
myCurrentIndex++;
return myHistory.get(myCurrentIndex);
}
return null;
throw new BrowserException("Invalid URL");
}

/**
* Returns the first page in back history, null if back history is empty.
*/
public URL back () {
public URL back () throws BrowserException {
if (hasPrevious()) {
myCurrentIndex--;
return myHistory.get(myCurrentIndex);
}
return null;
throw new BrowserException("Invalid URL");
}

/**
* Changes current page to given URL, removing next history.
*/
public URL go (String url) {
public URL go (String url) throws BrowserException {
myCurrentURL = completeURL(url);
if (myCurrentURL != null) {
if (hasNext()) {
Expand Down Expand Up @@ -115,15 +116,15 @@ public void addFavorite (String name) {
/**
* Returns URL from favorites associated with given name, null if none set.
*/
public URL getFavorite (String name) {
public URL getFavorite (String name) throws BrowserException {
if (name != null && !name.equals("") && myFavorites.containsKey(name)) {
return myFavorites.get(name);
}
return null;
throw new BrowserException("Invalid URL");
}

// deal with a potentially incomplete URL
private URL completeURL (String possible) {
private URL completeURL (String possible) throws BrowserException {
try {
// try it as is
return new URL(possible);
Expand All @@ -137,7 +138,7 @@ 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("Invalid URL");
}
}
}
Expand Down
39 changes: 34 additions & 5 deletions src/BrowserView.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public class BrowserView {
private Button myBackButton;
private Button myNextButton;
private Button myHomeButton;
private Button myFavoritesButton;
// favorites
private ComboBox<String> myFavorites;
// get strings from resource file
Expand Down Expand Up @@ -91,12 +92,22 @@ public BrowserView (BrowserModel model, String language) {
* 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 be) {
System.out.println("URL is not valid");
showError(String.format("The URL %s is not a valid URL", url));
}
}

Expand Down Expand Up @@ -126,12 +137,22 @@ public void showError (String message) {

// 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 @@ -140,7 +161,7 @@ private void home () {
}

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

Expand Down Expand Up @@ -221,10 +242,18 @@ public void handle (ActionEvent event) {
// make buttons for setting favorites/home URLs
private Node makePreferencesPanel () {
HBox result = new HBox();
myFavorites = new ComboBox<String>();
myFavorites.setPromptText("My Favorites");
result.getChildren().add(makeButton("SetHomeCommand", event -> {
myModel.setHome();
enableButtons();
}));
result.getChildren().add(makeButton("AddFavoriteCommand", event -> {
addFavorite();
enableButtons();
}));
result.getChildren().add(myFavorites);
// myFavorites.
return result;
}

Expand Down
2 changes: 1 addition & 1 deletion src/resources/default.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.root {
-fx-font-size: 14pt;
-fx-font-size: 24pt;
-fx-font-family: "Courier New";
-fx-base: rgb(132, 145, 47);
-fx-background: rgb(225, 228, 203);
Expand Down