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

bjk20, abz3, smk44 #53

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
28 changes: 17 additions & 11 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 @@ -200,17 +202,12 @@ private Node makeNavigationPanel () {
HBox result = new HBox();
// create buttons, with their associated actions
// old style way to do set up callback (anonymous class)
myBackButton = makeButton("BackCommand", new EventHandler<ActionEvent>() {
@Override
public void handle (ActionEvent event) {
back();
}
});
myBackButton = makeButton("BackCommand", "back");
result.getChildren().add(myBackButton);
// new style way to do set up callback (lambdas)
myNextButton = makeButton("NextCommand", event -> next());
myNextButton = makeButton("NextCommand", "next");
result.getChildren().add(myNextButton);
myHomeButton = makeButton("HomeCommand", event -> home());
myHomeButton = makeButton("HomeCommand", "home");
result.getChildren().add(myHomeButton);
// if user presses button or enter in text field, load/show the URL
EventHandler<ActionEvent> showHandler = new ShowPage();
Expand All @@ -226,7 +223,7 @@ private Node makePreferencesPanel () {
myFavorites = new ComboBox<String>();
myFavorites.setPromptText(myResources.getString("FavoriteFirstItem"));
myFavorites.valueProperty().addListener((o, s1, s2) -> showFavorite(s2));
result.getChildren().add(makeButton("AddFavoriteCommand", event -> addFavorite()));
result.getChildren().add(makeButton("AddFavoriteCommand", "addFavorite"));
result.getChildren().add(myFavorites);
result.getChildren().add(makeButton("SetHomeCommand", event -> {
myModel.setHome();
Expand All @@ -236,7 +233,7 @@ private Node makePreferencesPanel () {
}

// makes a button using either an image or a label
private Button makeButton (String property, EventHandler<ActionEvent> handler) {
private Button makeButton (String property, String methodName) throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
// represent all supported image suffixes
final String IMAGEFILE_SUFFIXES =
String.format(".*\\.(%s)", String.join("|", ImageIO.getReaderFileSuffixes()));
Expand All @@ -249,7 +246,16 @@ private Button makeButton (String property, EventHandler<ActionEvent> handler) {
} else {
result.setText(label);
}
result.setOnAction(handler);

Class noparams[] = {};
Class c = this.getClass();
Method method = c.getDeclaredMethod(methodName, noparams);
try {
result.setOnAction(event -> method.invoke(myModel, null));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}

Expand Down