Skip to content
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>
19 changes: 17 additions & 2 deletions src/BrowserView.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import java.awt.Dimension;
import java.lang.reflect.Method;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
import java.util.ResourceBundle;
import javafx.beans.value.ChangeListener;
Expand Down Expand Up @@ -31,6 +34,7 @@
import org.w3c.dom.events.EventTarget;



/**
* A class used to display the viewer for a simple HTML browser.
*
Expand Down Expand Up @@ -67,12 +71,14 @@ public class BrowserView {
private ResourceBundle myResources;
// the data
private BrowserModel myModel;
private Map<Button, Method> buttonToMethod;

/**
* Create a view of the given model of a web browser.
*/
public BrowserView (BrowserModel model, String language) {
myModel = model;
buttonToMethod = new HashMap<Button, Method>();
// use resources for labels
myResources = ResourceBundle.getBundle(DEFAULT_RESOURCE_PACKAGE + language);
BorderPane root = new BorderPane();
Expand Down Expand Up @@ -234,7 +240,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 method) throws NoSuchMethodException, SecurityException {
// represent all supported image suffixes
final String IMAGEFILE_SUFFIXES =
String.format(".*\\.(%s)", String.join("|", ImageIO.getReaderFileSuffixes()));
Expand All @@ -247,7 +253,16 @@ private Button makeButton (String property, EventHandler<ActionEvent> handler) {
} else {
result.setText(label);
}
result.setOnAction(handler);
Method methodToSet = this.getClass().getMethod(method);
buttonToMethod.put(result, methodToSet);
result.setOnAction(event -> {
try {
buttonToMethod.get(result).invoke(this, new Object[] {});
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
});
return result;
}

Expand Down