forked from GitHub/gf-core
Rename the GWT Translate module to PGF. Rename the GF class to PGF.
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
<!-- Inherit the core Web Toolkit stuff. -->
|
<!-- Inherit the core Web Toolkit stuff. -->
|
||||||
<inherits name="com.google.gwt.user.User" />
|
<inherits name="com.google.gwt.user.User" />
|
||||||
|
|
||||||
<inherits name="se.chalmers.cs.gf.gwt.Translate" />
|
<inherits name="se.chalmers.cs.gf.gwt.PGF" />
|
||||||
|
|
||||||
<!-- Inherit the default GWT style sheet. You can change -->
|
<!-- Inherit the default GWT style sheet. You can change -->
|
||||||
<!-- the theme of your GWT application by uncommenting -->
|
<!-- the theme of your GWT application by uncommenting -->
|
||||||
|
|||||||
@@ -8,21 +8,21 @@ import java.util.*;
|
|||||||
|
|
||||||
public class CompletionOracle extends SuggestOracle {
|
public class CompletionOracle extends SuggestOracle {
|
||||||
|
|
||||||
private GF gf;
|
private PGF pgf;
|
||||||
|
|
||||||
private ErrorHandler errorHandler;
|
private ErrorHandler errorHandler;
|
||||||
|
|
||||||
private List<String> inputLangs = null;
|
private List<String> inputLangs = null;
|
||||||
|
|
||||||
private GFRequest gfRequest = null;
|
private PGFRequest pgfRequest = null;
|
||||||
|
|
||||||
|
|
||||||
public CompletionOracle (GF gf) {
|
public CompletionOracle (PGF pgf) {
|
||||||
this(gf, null);
|
this(pgf, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompletionOracle (GF gf, ErrorHandler errorHandler) {
|
public CompletionOracle (PGF pgf, ErrorHandler errorHandler) {
|
||||||
this.gf = gf;
|
this.pgf = pgf;
|
||||||
this.errorHandler = errorHandler;
|
this.errorHandler = errorHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,12 +60,12 @@ public class CompletionOracle extends SuggestOracle {
|
|||||||
public void requestSuggestions(final SuggestOracle.Request request, final SuggestOracle.Callback callback) {
|
public void requestSuggestions(final SuggestOracle.Request request, final SuggestOracle.Callback callback) {
|
||||||
|
|
||||||
// only allow a single completion request at a time
|
// only allow a single completion request at a time
|
||||||
if (gfRequest != null)
|
if (pgfRequest != null)
|
||||||
gfRequest.cancel();
|
pgfRequest.cancel();
|
||||||
|
|
||||||
gfRequest = gf.complete(request.getQuery(), getInputLangs(), null, request.getLimit(),
|
pgfRequest = pgf.complete(request.getQuery(), getInputLangs(), null, request.getLimit(),
|
||||||
new GF.CompleteCallback() {
|
new PGF.CompleteCallback() {
|
||||||
public void onResult(GF.Completions completions) {
|
public void onResult(PGF.Completions completions) {
|
||||||
Collection<CompletionSuggestion> suggestions = new ArrayList<CompletionSuggestion>();
|
Collection<CompletionSuggestion> suggestions = new ArrayList<CompletionSuggestion>();
|
||||||
for (int i = 0; i < completions.length(); i++) {
|
for (int i = 0; i < completions.length(); i++) {
|
||||||
String text = completions.get(i).getText();
|
String text = completions.get(i).getText();
|
||||||
|
|||||||
@@ -15,12 +15,12 @@ import java.util.List;
|
|||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class GF {
|
public class PGF {
|
||||||
|
|
||||||
private String baseURL;
|
private String baseURL;
|
||||||
private String pgfName;
|
private String pgfName;
|
||||||
|
|
||||||
public GF (String baseURL, String pgfName) {
|
public PGF (String baseURL, String pgfName) {
|
||||||
this.baseURL = baseURL;
|
this.baseURL = baseURL;
|
||||||
this.pgfName = pgfName;
|
this.pgfName = pgfName;
|
||||||
}
|
}
|
||||||
@@ -58,7 +58,7 @@ public class GF {
|
|||||||
|
|
||||||
/* Grammar */
|
/* Grammar */
|
||||||
|
|
||||||
public GFRequest grammar (final GrammarCallback callback) {
|
public PGFRequest grammar (final GrammarCallback callback) {
|
||||||
return sendRequest("grammar", null, callback);
|
return sendRequest("grammar", null, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ public class GF {
|
|||||||
|
|
||||||
/* Translation */
|
/* Translation */
|
||||||
|
|
||||||
public GFRequest translate (String input, List<String> fromLangs, String cat, List<String> toLangs,
|
public PGFRequest translate (String input, List<String> fromLangs, String cat, List<String> toLangs,
|
||||||
final TranslateCallback callback) {
|
final TranslateCallback callback) {
|
||||||
List<Arg> args = new ArrayList<Arg>();
|
List<Arg> args = new ArrayList<Arg>();
|
||||||
args.add(new Arg("input", input));
|
args.add(new Arg("input", input));
|
||||||
@@ -128,7 +128,7 @@ public class GF {
|
|||||||
|
|
||||||
/* Completion */
|
/* Completion */
|
||||||
|
|
||||||
public GFRequest complete (String input, List<String> fromLangs, String cat, int limit, final CompleteCallback callback) {
|
public PGFRequest complete (String input, List<String> fromLangs, String cat, int limit, final CompleteCallback callback) {
|
||||||
List<Arg> args = new ArrayList<Arg>();
|
List<Arg> args = new ArrayList<Arg>();
|
||||||
args.add(new Arg("input", input));
|
args.add(new Arg("input", input));
|
||||||
if (fromLangs != null) {
|
if (fromLangs != null) {
|
||||||
@@ -156,7 +156,7 @@ public class GF {
|
|||||||
|
|
||||||
/* Utilities */
|
/* Utilities */
|
||||||
|
|
||||||
private <T extends JavaScriptObject> GFRequest sendRequest (String resource, List<Arg> vars, final GFCallback<T> callback) {
|
private <T extends JavaScriptObject> PGFRequest sendRequest (String resource, List<Arg> vars, final GFCallback<T> callback) {
|
||||||
String url = baseURL + "/" + pgfName + "/" + resource + "?" + buildQueryString(vars);
|
String url = baseURL + "/" + pgfName + "/" + resource + "?" + buildQueryString(vars);
|
||||||
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
|
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
|
||||||
builder.setTimeoutMillis(30000);
|
builder.setTimeoutMillis(30000);
|
||||||
@@ -182,7 +182,7 @@ public class GF {
|
|||||||
callback.onError(e);
|
callback.onError(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new GFRequest(request);
|
return new PGFRequest(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static native JavaScriptObject eval(String json) /*-{
|
private static native JavaScriptObject eval(String json) /*-{
|
||||||
@@ -2,11 +2,11 @@ package se.chalmers.cs.gf.gwt.client;
|
|||||||
|
|
||||||
import com.google.gwt.http.client.*;
|
import com.google.gwt.http.client.*;
|
||||||
|
|
||||||
public class GFRequest {
|
public class PGFRequest {
|
||||||
|
|
||||||
private Request httpRequest;
|
private Request httpRequest;
|
||||||
|
|
||||||
GFRequest (Request httpRequest) {
|
PGFRequest (Request httpRequest) {
|
||||||
this.httpRequest = httpRequest;
|
this.httpRequest = httpRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -30,14 +30,14 @@ import java.util.Set;
|
|||||||
|
|
||||||
public class TranslateApp implements EntryPoint {
|
public class TranslateApp implements EntryPoint {
|
||||||
|
|
||||||
private static final String gfBaseURL = "/pgf";
|
private static final String pgfBaseURL = "/pgf";
|
||||||
private static final String pgfName = "grammar.pgf";
|
private static final String pgfName = "grammar.pgf";
|
||||||
|
|
||||||
private GF gf;
|
private PGF pgf;
|
||||||
|
|
||||||
private CompletionOracle oracle;
|
private CompletionOracle oracle;
|
||||||
private SuggestBox suggest;
|
private SuggestBox suggest;
|
||||||
private GF.Grammar grammar;
|
private PGF.Grammar grammar;
|
||||||
private ListBox fromLangBox;
|
private ListBox fromLangBox;
|
||||||
private ListBox toLangBox;
|
private ListBox toLangBox;
|
||||||
private Button translateButton;
|
private Button translateButton;
|
||||||
@@ -48,7 +48,7 @@ public class TranslateApp implements EntryPoint {
|
|||||||
private void addTranslation(String text, String toLang) {
|
private void addTranslation(String text, String toLang) {
|
||||||
Label l = new Label(text);
|
Label l = new Label(text);
|
||||||
l.addStyleName("my-translation");
|
l.addStyleName("my-translation");
|
||||||
GF.Language lang = grammar.getLanguage(toLang);
|
PGF.Language lang = grammar.getLanguage(toLang);
|
||||||
if (lang != null) {
|
if (lang != null) {
|
||||||
l.getElement().setLang(lang.getLanguageCode());
|
l.getElement().setLang(lang.getLanguageCode());
|
||||||
}
|
}
|
||||||
@@ -58,10 +58,10 @@ public class TranslateApp implements EntryPoint {
|
|||||||
private void translate() {
|
private void translate() {
|
||||||
outputPanel.clear();
|
outputPanel.clear();
|
||||||
setStatus("Translating...");
|
setStatus("Translating...");
|
||||||
gf.translate(suggest.getText(), listBoxSelection(fromLangBox), null,
|
pgf.translate(suggest.getText(), listBoxSelection(fromLangBox), null,
|
||||||
listBoxSelection(toLangBox), new GF.TranslateCallback() {
|
listBoxSelection(toLangBox), new PGF.TranslateCallback() {
|
||||||
public void onResult (GF.Translations translations) {
|
public void onResult (PGF.Translations translations) {
|
||||||
for (GF.Translation t : translations.iterable()) {
|
for (PGF.Translation t : translations.iterable()) {
|
||||||
addTranslation(t.getText(), t.getTo());
|
addTranslation(t.getText(), t.getTo());
|
||||||
}
|
}
|
||||||
clearStatus();
|
clearStatus();
|
||||||
@@ -101,10 +101,10 @@ public class TranslateApp implements EntryPoint {
|
|||||||
statusPopup.hide();
|
statusPopup.hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setGrammar(GF.Grammar grammar) {
|
private void setGrammar(PGF.Grammar grammar) {
|
||||||
this.grammar = grammar;
|
this.grammar = grammar;
|
||||||
|
|
||||||
for (GF.Language l : grammar.getLanguages().iterable()) {
|
for (PGF.Language l : grammar.getLanguages().iterable()) {
|
||||||
String name = l.getName();
|
String name = l.getName();
|
||||||
if (l.canParse()) {
|
if (l.canParse()) {
|
||||||
fromLangBox.addItem(name);
|
fromLangBox.addItem(name);
|
||||||
@@ -124,7 +124,7 @@ public class TranslateApp implements EntryPoint {
|
|||||||
|
|
||||||
private void createTranslationUI() {
|
private void createTranslationUI() {
|
||||||
|
|
||||||
oracle = new CompletionOracle(gf, new CompletionOracle.ErrorHandler() {
|
oracle = new CompletionOracle(pgf, new CompletionOracle.ErrorHandler() {
|
||||||
public void onError(Throwable e) {
|
public void onError(Throwable e) {
|
||||||
showError("Completion failed", e);
|
showError("Completion failed", e);
|
||||||
}
|
}
|
||||||
@@ -196,12 +196,12 @@ public class TranslateApp implements EntryPoint {
|
|||||||
statusPopup.add(statusLabel);
|
statusPopup.add(statusLabel);
|
||||||
statusPopup.center();
|
statusPopup.center();
|
||||||
|
|
||||||
gf = new GF(gfBaseURL, pgfName);
|
pgf = new PGF(pgfBaseURL, pgfName);
|
||||||
|
|
||||||
createTranslationUI();
|
createTranslationUI();
|
||||||
|
|
||||||
gf.grammar(new GF.GrammarCallback() {
|
pgf.grammar(new PGF.GrammarCallback() {
|
||||||
public void onResult(GF.Grammar grammar) {
|
public void onResult(PGF.Grammar grammar) {
|
||||||
setGrammar(grammar);
|
setGrammar(grammar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user