/**
* This is the entry point method.
*/
public void onModuleLoad() {
final Button sendButton = new Button("Send to Havlak");
final TextBox nameField = new TextBox();
nameField.setText("GWT User");
final Label errorLabel = new Label();
// We can add style names to widgets
sendButton.addStyleName("sendButton");
// Add the nameField and sendButton to the RootPanel
// Use RootPanel.get() to get the entire body element
RootPanel.get("nameFieldContainer").add(nameField);
RootPanel.get("sendButtonContainer").add(sendButton);
RootPanel.get("errorLabelContainer").add(errorLabel);
// Focus the cursor on the name field when the app loads
nameField.setFocus(true);
nameField.selectAll();
// Create the popup dialog box
final DialogBox dialogBox = new DialogBox();
dialogBox.setText("Loop Recognition");
dialogBox.setAnimationEnabled(true);
final Button closeButton = new Button("Close");
// We can set the id of a widget by accessing its Element
closeButton.getElement().setId("closeButton");
final Label textToServerLabel = new Label();
final HTML serverResponseLabel = new HTML();
VerticalPanel dialogVPanel = new VerticalPanel();
dialogVPanel.addStyleName("dialogVPanel");
dialogVPanel.add(textToServerLabel);
dialogVPanel.add(new HTML("<br><b>Algorithm replies:</b>"));
dialogVPanel.add(serverResponseLabel);
dialogVPanel.setHorizontalAlignment(VerticalPanel.ALIGN_RIGHT);
dialogVPanel.add(closeButton);
dialogBox.setWidget(dialogVPanel);
// Add a handler to close the DialogBox
closeButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
dialogBox.hide();
sendButton.setEnabled(true);
sendButton.setFocus(true);
}
});
// Create a handler for the sendButton and nameField
class MyHandler implements ClickHandler, KeyUpHandler {
/**
* Fired when the user clicks on the sendButton.
*/
public void onClick(ClickEvent event) {
sendNameToServer();
}
/**
* Fired when the user types in the nameField.
*/
public void onKeyUp(KeyUpEvent event) {
if (event.getNativeKeyCode() == KeyCodes.KEY_ENTER) {
sendNameToServer();
}
}
/**
* Send the name from the nameField to the server and wait for a response.
*/
private void sendNameToServer() {
// First, we validate the input.
errorLabel.setText("");
String textToServer = nameField.getText();
//=======================================================
// HAVLAK
//=======================================================
long start = System.currentTimeMillis();
String result = "Welcome to LoopTesterApp, GWT edition<br>";
LoopTesterApp app = new LoopTesterApp();
app.cfg.createNode(0);
app.lsg.dump();
app.buildBaseLoop(0);
app.cfg.createNode(1);
new BasicBlockEdge(app.cfg, 0, 2);
int found = 0;
result += "15000 dummy loops<br>";
serverResponseLabel.setHTML(result);
for (int dummyloop = 0; dummyloop < 1; dummyloop++) {
HavlakLoopFinder finder = new HavlakLoopFinder(app.cfg, app.lsg);
finder.findLoops();
}
result += "Constructing CFG...<br>";
serverResponseLabel.setHTML(result);
int n = 2;
for (int parlooptrees = 0; parlooptrees < 10; parlooptrees++) {
app.cfg.createNode(n + 1);
app.buildConnect(2, n + 1);
n = n + 1;
for (int i = 0; i < 2; i++) {
int top = n;
n = app.buildStraight(n, 1);
for (int j = 0; j < 25; j++) {
n = app.buildBaseLoop(n);
}
int bottom = app.buildStraight(n, 1);
app.buildConnect(n, top);
n = bottom;
}
app.buildConnect(n, 1);
}
result += "Performing Loop Recognition\n1 Iteration<br>";
HavlakLoopFinder finder = new HavlakLoopFinder(app.cfg, app.lsg);
finder.findLoops();
long t = System.currentTimeMillis() - start;
result += "Found: " + app.lsg.getNumLoops() + " in " +
t + " [ms]";
result += "Another 100 iterations...<br>";
for (int i = 0; i < 100; i++) {
HavlakLoopFinder finder2 = new HavlakLoopFinder(app.cfg, new LSG());
finder2.findLoops();
}
t = System.currentTimeMillis() - start;
result += "<br>Found: " + app.lsg.getNumLoops() + " in " +
t + " [ms]";
//=======================================================
sendButton.setEnabled(false);
dialogBox.setText("Find Loops");
serverResponseLabel.setHTML(result);
dialogBox.center();
closeButton.setFocus(true);
/*
// if (!FieldVerifier.isValidName(textToServer)) {
// errorLabel.setText("Please enter at least four characters");
// return;