/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package com.wefend.pc.testcase; import com.intuism.ui.autocorrection.Corrector; import com.intuism.ui.autocorrection.phonenumber.DanishPhoneNumberCorrector; import com.intuism.ui.autocorrection.phonenumber.GlobalPhoneNumberCorrector; import com.intuism.ui.autocorrection.phonenumber.UsPhoneNumberCorrector; import com.intuism.ui.autocorrection.time.TimeCorrector; import com.intuism.ui.form.text.caret.Caret; import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.layout.GridPane; import javafx.stage.Stage; import quicktime.std.clocks.TimeCallBack; /** * * @author Randahl Fink Isaksen */ public class AutocorrectionDemo extends Application { private class ITextField extends TextField { private boolean correcting = false; private Caret caret = new Caret(this); private Corrector corrector; public ITextField(Corrector corrector) { this.corrector = corrector; } @Override public void replaceText(int start, int end, String text) { super.replaceText(start, end, text); correct(); } @Override public void replaceSelection(String string) { super.replaceSelection(string); correct(); } protected void correct() { if(corrector != null && !correcting) { try { correcting = true; corrector.correct(caret); } finally { correcting = false; } } } }; @Override public void start(Stage stage) throws Exception { GridPane grid = new GridPane(); ITextField danishPhoneNumberField = new ITextField(DanishPhoneNumberCorrector.getInstance()); Label danishLabel = new Label("Danish phone number:"); grid.add(danishLabel, 0, 0); grid.add(danishPhoneNumberField, 1, 0); ITextField usPhoneNumberField = new ITextField(UsPhoneNumberCorrector.getInstance()); Label usLabel = new Label("US Phone number:"); grid.add(usLabel, 0, 1); grid.add(usPhoneNumberField, 1, 1); ITextField globalPhoneNumberField = new ITextField(GlobalPhoneNumberCorrector.getInstance()); Label globalLabel = new Label("Any global phone number:"); grid.add(globalLabel, 0, 2); grid.add(globalPhoneNumberField, 1, 2); ITextField timeField = new ITextField(TimeCorrector.getInstance()); Label timeLabel = new Label("Time of day:"); grid.add(timeLabel, 0, 3); grid.add(timeField, 1, 3); stage.setWidth(400); stage.setScene(new Scene(grid)); stage.show(); } public static void main(String[] args) { Application.launch(args); } }