<commit_before>package com.github.donkirkby.vograbulary.client;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import com.github.donkirkby.vograbulary.ultraghost.ComputerStudent;
import com.github.donkirkby.vograbulary.ultraghost.Controller;
import com.github.donkirkby.vograbulary.ultraghost.Match;
import com.github.donkirkby.vograbulary.ultraghost.Puzzle;
import com.github.donkirkby.vograbulary.ultraghost.Student;
import com.github.donkirkby.vograbulary.ultraghost.UltraghostScreen;
import com.github.donkirkby.vograbulary.ultraghost.WordList;
import com.github.donkirkby.vograbulary.ultraghost.WordResult;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.DivElement;
import com.google.gwt.dom.client.ParagraphElement;
import com.google.gwt.dom.client.SpanElement;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;

public class UltraghostPresenter extends VograbularyPresenter implements UltraghostScreen {
    public static final String HISTORY_TOKEN = "<PASSWORD>";
    public static final String HISTORY_TOKEN_HYPER = "hyperghost";

    private static UltraghostPresenterUiBinder uiBinder = GWT
            .create(UltraghostPresenterUiBinder.class);

    interface UltraghostPresenterUiBinder extends
            UiBinder<Widget, UltraghostPresenter> {
    }
    
    @UiField
    ParagraphElement ownerName;
    
    @UiField
    ParagraphElement letters;
    
    @UiField
    TextBox solution;
    
    @UiField
    Button solveButton;
    
    @UiField
    TextBox response;
    
    @UiField
    Button respondButton;
    
    @UiField
    SpanElement hint;
    
    @UiField
    Button nextButton;
    
    @UiField
    ParagraphElement result;
    
    @UiField
    DivElement summary;
    
    private Controller controller = 
            new Controller();
    private Match match;
    private List<Button> focusButtons;
    private GwtPreferences preferences;

    public UltraghostPresenter(GwtPreferences preferences) {
        initWidget(uiBinder.createAndBindUi(this));

        this.preferences = preferences;
        String wordListText = Assets.INSTANCE.wordList().getText();
        WordList wordList = new WordList();
        wordList.read(Arrays.asList(wordListText.split("\\n")));
        controller.setWordList(wordList);
        controller.setScheduler(new GwtScheduler());

//      Match match = controller.getMatch();
//      match.setMinimumWordLength(
//              preferences.getUltraghostMinimumWordLength());
//      match.setHyperghost(isHyperghost);
  
        focusButtons = Arrays.asList(solveButton, respondButton, nextButton);
        
        controller.setScreen(this);
    }
    
    @Override
    protected void onLoad() {
        super.onLoad();
        controller.start();
    }
    
    @UiHandler("solveButton")
    void solve(ClickEvent e) {
        match.getPuzzle().setSolution(solution.getText());
        controller.solve();
    }
    
    @UiHandler("respondButton")
    void respond(ClickEvent e) {
        match.getPuzzle().setResponse(response.getText());
    }
    
    @UiHandler("nextButton")
    void next(ClickEvent e) {
        controller.start();
    }
//      table.addListener(new InputListener() {
//          @Override
//          public boolean keyUp(InputEvent event, int keycode) {
//              if (keycode == Input.Keys.ENTER) {
//                  ChangeListener.ChangeEvent changeEvent = 
//                          new ChangeListener.ChangeEvent();
//                  for (TextButton button : focusButtons) {
//                      if (button.isVisible()) {
//                          button.fire(changeEvent);
//                          return true;
//                      }
//                  }
//              }
//              return false;
//          }
//      });
//      // On some platforms, setting the focus in an enter key handler is
//      // not compatible with the default focus traversal. Disable it.
//      solution.setFocusTraversal(false);
//      response.setFocusTraversal(false);
//      
//      focusNextButton();
//  }
//  
//  public void clear() {
//      studentName.setText(" ");
//      letters.setText(" ");
//      solution.setText("");
//      response.setText("");
//      hint.setText(" ");
//      result.setText("");
//      scores.setText("");
//  }

    private void focusButton(Button target) {
        Student winner = match.getWinner();
        for (Button button : focusButtons) {
            button.setVisible(winner == null && button == target);
        }
    }

    @Override
    public void clear() {
    }
    
    @Override
    public void focusSolution() {
        focusButton(solveButton);
        solution.setFocus(true);
    }
    
    @Override
    public void focusResponse() {
        focusButton(respondButton);
        response.setFocus(true);
    }
    
    @Override
    public void focusNextButton() {
        focusButton(nextButton);
        nextButton.setFocus(true);
    }
    
    @Override
    public void showThinking() {
        focusButton(null);
    }
    <commit_msg>Enter key in HTML Ultraghost for issue #40.<commit_after>package com.github.donkirkby.vograbulary.client;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import com.github.donkirkby.vograbulary.ultraghost.ComputerStudent;
import com.github.donkirkby.vograbulary.ultraghost.Controller;
import com.github.donkirkby.vograbulary.ultraghost.Match;
import com.github.donkirkby.vograbulary.ultraghost.Puzzle;
import com.github.donkirkby.vograbulary.ultraghost.Student;
import com.github.donkirkby.vograbulary.ultraghost.UltraghostScreen;
import com.github.donkirkby.vograbulary.ultraghost.WordList;
import com.github.donkirkby.vograbulary.ultraghost.WordResult;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.DivElement;
import com.google.gwt.dom.client.ParagraphElement;
import com.google.gwt.dom.client.SpanElement;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyPressEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;

public class UltraghostPresenter extends VograbularyPresenter implements UltraghostScreen {
    public static final String HISTORY_TOKEN = "<PASSWORD>";
    public static final String HISTORY_TOKEN_HYPER = "<PASSWORD>";

    private static UltraghostPresenterUiBinder uiBinder = GWT
            .create(UltraghostPresenterUiBinder.class);

    interface UltraghostPresenterUiBinder extends
            UiBinder<Widget, UltraghostPresenter> {
    }
    
    @UiField
    ParagraphElement ownerName;
    
    @UiField
    ParagraphElement letters;
    
    @UiField
    TextBox solution;
    
    @UiField
    Button solveButton;
    
    @UiField
    TextBox response;
    
    @UiField
    Button respondButton;
    
    @UiField
    SpanElement hint;
    
    @UiField
    Button nextButton;
    
    @UiField
    ParagraphElement result;
    
    @UiField
    DivElement summary;
    
    private Controller controller = 
            new Controller();
    private Match match;
    private List<Button> focusButtons;
    private List<TextBox> focusFields;
    private GwtPreferences preferences;

    public UltraghostPresenter(GwtPreferences preferences) {
        initWidget(uiBinder.createAndBindUi(this));

        this.preferences = preferences;
        String wordListText = Assets.INSTANCE.wordList().getText();
        WordList wordList = new WordList();
        wordList.read(Arrays.asList(wordListText.split("\\n")));
        controller.setWordList(wordList);
        controller.setScheduler(new GwtScheduler());

//      Match match = controller.getMatch();
//      match.setMinimumWordLength(
//              preferences.getUltraghostMinimumWordLength());
//      match.setHyperghost(isHyperghost);
  
        focusButtons = Arrays.asList(solveButton, respondButton, nextButton);
        focusFields = Arrays.asList(solution, response);
        
        controller.setScreen(this);
    }
    
    @Override
    protected void onLoad() {
        super.onLoad();
        controller.start();
    }
    
    @UiHandler("solution")
    void solutionKeyPress(KeyPressEvent e) {
        if (e.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
            solve(null);
        }
    }
    
    @UiHandler("solveButton")
    void solve(ClickEvent e) {
        match.getPuzzle().setSolution(solution.getText());
        controller.solve();
    }
    
    @UiHandler("response")
    void responseKeyPress(KeyPressEvent e) {
        if (e.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
            respond(null);
        }
    }
    
    @UiHandler("respondButton")
    void respond(ClickEvent e) {
        match.getPuzzle().setResponse(response.getText());
    }
    
    @UiHandler("nextButton")
    void next(ClickEvent e) {
        controller.start();
    }
    
    private void focusField(TextBox target) {
        for (TextBox field : focusFields) {
            field.setEnabled(target == field);
        }
        if (target != null) {
            target.setFocus(true);
        }
    }

    private void focusButton(Button target) {
        Student winner = match.getWinner();
        for (Button button : focusButtons) {
            button.setVisible(winner == null && button == target);
        }
    }

    @Override
    public void clear() {
    }
    
    @Override
    public void focusSolution() {
        focusButton(solveButton);
        focusField(solution);
    }
    
    @Override
    public void focusResponse() {
        focusButton(respondButton);
        focusField(response);
    }
    
    @Override
    public void focusNextButton() {
        focusButton(nextButton);
        focusField(null);
        nextButton.setFocus(true);
    }
    
    @Override
    public void showThinking() {
        focusButton(null);
    }
    
{'fraction_non_alphanumeric': 0.10576738838858019, 'fraction_numerical': 0.00019160758766047136, 'mean_word_length': 2.623394654633808, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5938034', 'n_tokens_mistral': 3115, 'n_tokens_neox': 3072, 'n_words': 533}