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>
37 changes: 37 additions & 0 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 @@ -250,6 +252,41 @@ private Button makeButton (String property, EventHandler<ActionEvent> handler) {
result.setOnAction(handler);
return result;
}

private Button makeButton (String property, String handler) {
final String IMAGEFILE_SUFFIXES =
String.format(".*\\.(%s)", String.join("|", ImageIO.getReaderFileSuffixes()));

Button result = new Button();
String label = myResources.getString(property);
if (label.matches(IMAGEFILE_SUFFIXES)) {
result.setGraphic(new ImageView(
new Image(getClass().getResourceAsStream(DEFAULT_RESOURCE_PACKAGE + label))));
} else {
result.setText(label);
}
try{
Method method = this.getClass().getMethod(handler);
try{
result.setOnAction((EventHandler<ActionEvent>) method.invoke(this));
}
catch (IllegalAccessException e) {
showError("Unable to create button due to faulty method string.");
} catch (InvocationTargetException e) {
showError("Unable to create button due to faulty method string.");
}
}
catch (SecurityException e){
showError("Unable to create button due to faulty method string.");
result = null;
}
catch (NoSuchMethodException e){
showError("Unable to create button due to faulty method string.");
result = null;
}
return result;
}


// make text field for input
private TextField makeInputField (int width, EventHandler<ActionEvent> handler) {
Expand Down