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

Added reflected makeButtons method plg5 cft6 bcw22 #49

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>
30 changes: 21 additions & 9 deletions src/BrowserView.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -155,15 +156,15 @@ 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<String> response = input.showAndWait();
// did user make a choice?
if (response.isPresent()) {
myModel.addFavorite(response.get());
myFavorites.getItems().add(response.get());
}
}*/
}

// only enable buttons when useful to user
Expand Down Expand Up @@ -236,7 +237,8 @@ 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, EventHandler<ActionEvent> handler) {
private Button makeButton (String property, String handler) {
// represent all supported image suffixes
final String IMAGEFILE_SUFFIXES =
String.format(".*\\.(%s)", String.join("|", ImageIO.getReaderFileSuffixes()));
Expand All @@ -249,7 +251,17 @@ private Button makeButton (String property, EventHandler<ActionEvent> 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;
}

Expand Down