1
0
forked from GitHub/gf-core

Rename the GWT Translate module to PGF. Rename the GF class to PGF.

This commit is contained in:
bjorn
2008-10-22 12:05:59 +00:00
parent 792752c382
commit 22c271ad70
6 changed files with 35 additions and 35 deletions

View File

@@ -3,7 +3,7 @@
<!-- Inherit the core Web Toolkit stuff. -->
<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 -->
<!-- the theme of your GWT application by uncommenting -->

View File

@@ -8,21 +8,21 @@ import java.util.*;
public class CompletionOracle extends SuggestOracle {
private GF gf;
private PGF pgf;
private ErrorHandler errorHandler;
private List<String> inputLangs = null;
private GFRequest gfRequest = null;
private PGFRequest pgfRequest = null;
public CompletionOracle (GF gf) {
this(gf, null);
public CompletionOracle (PGF pgf) {
this(pgf, null);
}
public CompletionOracle (GF gf, ErrorHandler errorHandler) {
this.gf = gf;
public CompletionOracle (PGF pgf, ErrorHandler errorHandler) {
this.pgf = pgf;
this.errorHandler = errorHandler;
}
@@ -60,12 +60,12 @@ public class CompletionOracle extends SuggestOracle {
public void requestSuggestions(final SuggestOracle.Request request, final SuggestOracle.Callback callback) {
// only allow a single completion request at a time
if (gfRequest != null)
gfRequest.cancel();
if (pgfRequest != null)
pgfRequest.cancel();
gfRequest = gf.complete(request.getQuery(), getInputLangs(), null, request.getLimit(),
new GF.CompleteCallback() {
public void onResult(GF.Completions completions) {
pgfRequest = pgf.complete(request.getQuery(), getInputLangs(), null, request.getLimit(),
new PGF.CompleteCallback() {
public void onResult(PGF.Completions completions) {
Collection<CompletionSuggestion> suggestions = new ArrayList<CompletionSuggestion>();
for (int i = 0; i < completions.length(); i++) {
String text = completions.get(i).getText();

View File

@@ -15,12 +15,12 @@ import java.util.List;
import java.util.NoSuchElementException;
import java.util.ArrayList;
public class GF {
public class PGF {
private String baseURL;
private String pgfName;
public GF (String baseURL, String pgfName) {
public PGF (String baseURL, String pgfName) {
this.baseURL = baseURL;
this.pgfName = pgfName;
}
@@ -58,7 +58,7 @@ public class GF {
/* Grammar */
public GFRequest grammar (final GrammarCallback callback) {
public PGFRequest grammar (final GrammarCallback callback) {
return sendRequest("grammar", null, callback);
}
@@ -94,7 +94,7 @@ public class GF {
/* 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) {
List<Arg> args = new ArrayList<Arg>();
args.add(new Arg("input", input));
@@ -128,7 +128,7 @@ public class GF {
/* 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>();
args.add(new Arg("input", input));
if (fromLangs != null) {
@@ -156,7 +156,7 @@ public class GF {
/* 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);
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
builder.setTimeoutMillis(30000);
@@ -182,7 +182,7 @@ public class GF {
callback.onError(e);
}
return new GFRequest(request);
return new PGFRequest(request);
}
private static native JavaScriptObject eval(String json) /*-{

View File

@@ -2,11 +2,11 @@ package se.chalmers.cs.gf.gwt.client;
import com.google.gwt.http.client.*;
public class GFRequest {
public class PGFRequest {
private Request httpRequest;
GFRequest (Request httpRequest) {
PGFRequest (Request httpRequest) {
this.httpRequest = httpRequest;
}

View File

@@ -30,14 +30,14 @@ import java.util.Set;
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 GF gf;
private PGF pgf;
private CompletionOracle oracle;
private SuggestBox suggest;
private GF.Grammar grammar;
private PGF.Grammar grammar;
private ListBox fromLangBox;
private ListBox toLangBox;
private Button translateButton;
@@ -48,7 +48,7 @@ public class TranslateApp implements EntryPoint {
private void addTranslation(String text, String toLang) {
Label l = new Label(text);
l.addStyleName("my-translation");
GF.Language lang = grammar.getLanguage(toLang);
PGF.Language lang = grammar.getLanguage(toLang);
if (lang != null) {
l.getElement().setLang(lang.getLanguageCode());
}
@@ -58,10 +58,10 @@ public class TranslateApp implements EntryPoint {
private void translate() {
outputPanel.clear();
setStatus("Translating...");
gf.translate(suggest.getText(), listBoxSelection(fromLangBox), null,
listBoxSelection(toLangBox), new GF.TranslateCallback() {
public void onResult (GF.Translations translations) {
for (GF.Translation t : translations.iterable()) {
pgf.translate(suggest.getText(), listBoxSelection(fromLangBox), null,
listBoxSelection(toLangBox), new PGF.TranslateCallback() {
public void onResult (PGF.Translations translations) {
for (PGF.Translation t : translations.iterable()) {
addTranslation(t.getText(), t.getTo());
}
clearStatus();
@@ -101,10 +101,10 @@ public class TranslateApp implements EntryPoint {
statusPopup.hide();
}
private void setGrammar(GF.Grammar grammar) {
private void setGrammar(PGF.Grammar grammar) {
this.grammar = grammar;
for (GF.Language l : grammar.getLanguages().iterable()) {
for (PGF.Language l : grammar.getLanguages().iterable()) {
String name = l.getName();
if (l.canParse()) {
fromLangBox.addItem(name);
@@ -124,7 +124,7 @@ public class TranslateApp implements EntryPoint {
private void createTranslationUI() {
oracle = new CompletionOracle(gf, new CompletionOracle.ErrorHandler() {
oracle = new CompletionOracle(pgf, new CompletionOracle.ErrorHandler() {
public void onError(Throwable e) {
showError("Completion failed", e);
}
@@ -196,12 +196,12 @@ public class TranslateApp implements EntryPoint {
statusPopup.add(statusLabel);
statusPopup.center();
gf = new GF(gfBaseURL, pgfName);
pgf = new PGF(pgfBaseURL, pgfName);
createTranslationUI();
gf.grammar(new GF.GrammarCallback() {
public void onResult(GF.Grammar grammar) {
pgf.grammar(new PGF.GrammarCallback() {
public void onResult(PGF.Grammar grammar) {
setGrammar(grammar);
}