From bb0c9ab7d17ebe58d3bab9c00ebc885ac658755a Mon Sep 17 00:00:00 2001 From: Patrick Grady Date: Thu, 3 Mar 2016 17:50:56 -0500 Subject: [PATCH] Added reflected makeButtons method --- .classpath | 6 ++++++ src/BrowserView.java | 30 +++++++++++++++++++++--------- 2 files changed, 27 insertions(+), 9 deletions(-) create mode 100644 .classpath diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..fb50116 --- /dev/null +++ b/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/BrowserView.java b/src/BrowserView.java index 7d59606..b7fbd92 100644 --- a/src/BrowserView.java +++ b/src/BrowserView.java @@ -1,4 +1,5 @@ import java.awt.Dimension; +import java.lang.reflect.Method; import java.net.URL; import java.util.Optional; import java.util.ResourceBundle; @@ -10,13 +11,13 @@ import javafx.event.EventHandler; import javafx.scene.Node; import javafx.scene.Scene; -import javafx.scene.control.Alert; -import javafx.scene.control.Alert.AlertType; +//import javafx.scene.control.Alert; +//import javafx.scene.control.Alert.AlertType; import javafx.scene.control.Button; import javafx.scene.control.ComboBox; import javafx.scene.control.Label; import javafx.scene.control.TextField; -import javafx.scene.control.TextInputDialog; +//import javafx.scene.control.TextInputDialog; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.layout.BorderPane; @@ -117,10 +118,10 @@ public void showStatus (String message) { * Display given message as an error in the GUI. */ public void showError (String message) { - Alert alert = new Alert(AlertType.ERROR); + /*Alert alert = new Alert(AlertType.ERROR); alert.setTitle(myResources.getString("ErrorTitle")); alert.setContentText(message); - alert.showAndWait(); + alert.showAndWait();*/ } // move to the next URL in the history @@ -155,7 +156,7 @@ private void update (URL url) { // prompt user for name of favorite to add to collection private void addFavorite () { - TextInputDialog input = new TextInputDialog(""); + /*TextInputDialog input = new TextInputDialog(""); input.setTitle(myResources.getString("FavoritePromptTitle")); input.setContentText(myResources.getString("FavoritePrompt")); Optional response = input.showAndWait(); @@ -163,7 +164,7 @@ private void addFavorite () { if (response.isPresent()) { myModel.addFavorite(response.get()); myFavorites.getItems().add(response.get()); - } + }*/ } // only enable buttons when useful to user @@ -236,7 +237,8 @@ private Node makePreferencesPanel () { } // makes a button using either an image or a label - private Button makeButton (String property, EventHandler handler) { + //private Button makeButton (String property, EventHandler handler) { + private Button makeButton (String property, String handler) { // represent all supported image suffixes final String IMAGEFILE_SUFFIXES = String.format(".*\\.(%s)", String.join("|", ImageIO.getReaderFileSuffixes())); @@ -249,7 +251,17 @@ private Button makeButton (String property, EventHandler handler) { } else { result.setText(label); } - result.setOnAction(handler); + + Method m; + try { + m = this.getClass().getMethod(handler); + } catch (NoSuchMethodException | SecurityException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + //m.invoke(this); + + result.setOnAction(e -> m.invoke(this)); return result; }