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>
59 changes: 41 additions & 18 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,21 +202,16 @@ 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();
result.getChildren().add(makeButton("GoCommand", showHandler));
result.getChildren().add(makeButton("GoCommand", "handleShow"));
myURLDisplay = makeInputField(40, showHandler);
result.getChildren().add(myURLDisplay);
return result;
Expand All @@ -226,30 +223,52 @@ 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();
enableButtons();
}));
result.getChildren().add(makeButton("SetHomeCommand", "handleSetHome"));
return result;
}

private void handleSetHome() {
myModel.setHome();
enableButtons();
}

// makes a button using either an image or a label
private Button makeButton (String property, EventHandler<ActionEvent> handler) {

private Button makeButton (String property, String handler ){ //[EventHandler<ActionEvent> handler) {
// represent all supported image suffixes
final String IMAGEFILE_SUFFIXES =
String.format(".*\\.(%s)", String.join("|", ImageIO.getReaderFileSuffixes()));
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))));
new Image(getClass().getResourceAsStream(DEFAULT_RESOURCE_PACKAGE + label))));
} else {
result.setText(label);
}
result.setOnAction(handler);
// Class<?> c = Class.forName(args[);
//Class[] argTypes = new Class[] { String[].class };
Method method = null;

try {
method = this.getClass().getDeclaredMethod(handler);
//main.invoke(this);
//result.setOnAction( e -> method.invoke(this));
}
catch (ReflectiveOperationException | IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

//String[] mainArgs = Arrays.copyOfRange(args, 1, args.length);
//System.out.format("invoking %s.main()%n", c.getName());
//main.invoke(null);



return result;
}

Expand All @@ -269,6 +288,10 @@ public void handle (ActionEvent event) {
showPage(myURLDisplay.getText());
}
}

private void handleShow() {
showPage(myURLDisplay.getText());
}


// Inner class to deal with link-clicks and mouse-overs Mostly taken from
Expand Down