mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-20 16:42:51 -06:00
revert the TranslateApp to its classical simple variant
This commit is contained in:
@@ -1,153 +0,0 @@
|
|||||||
package org.grammaticalframework.ui.gwt.client;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import com.google.gwt.user.client.ui.*;
|
|
||||||
import com.google.gwt.http.client.*;
|
|
||||||
|
|
||||||
public class BrowsePanel extends Composite {
|
|
||||||
|
|
||||||
private PGFWrapper pgf;
|
|
||||||
private HTML sourceView;
|
|
||||||
private SuggestBox searchBox;
|
|
||||||
private CompletionOracle oracle;
|
|
||||||
private List<String> identifiers = null;
|
|
||||||
|
|
||||||
public BrowsePanel(PGFWrapper pgf) {
|
|
||||||
this.pgf = pgf;
|
|
||||||
|
|
||||||
oracle = new CompletionOracle();
|
|
||||||
|
|
||||||
HorizontalPanel browsePanel = new HorizontalPanel();
|
|
||||||
browsePanel.add(createSearchPanel(oracle));
|
|
||||||
browsePanel.add(createSourcePanel());
|
|
||||||
browsePanel.setCellWidth(sourceView,"100%");
|
|
||||||
|
|
||||||
initWidget(browsePanel);
|
|
||||||
setStylePrimaryName("my-BrowsePanel");
|
|
||||||
|
|
||||||
pgf.addSettingsListener(new MySettingsListener(pgf));
|
|
||||||
}
|
|
||||||
|
|
||||||
public native void onActivate() /*-{
|
|
||||||
$doc.browsePanel = this;
|
|
||||||
$doc.callBrowse = @org.grammaticalframework.ui.gwt.client.BrowsePanel::callBrowse(Lorg/grammaticalframework/ui/gwt/client/BrowsePanel;Ljava/lang/String;);
|
|
||||||
}-*/;
|
|
||||||
|
|
||||||
protected Widget createSearchPanel(CompletionOracle oracle) {
|
|
||||||
searchBox = new SuggestBox(oracle);
|
|
||||||
searchBox.setLimit(10);
|
|
||||||
searchBox.addKeyboardListener(new KeyboardListenerAdapter() {
|
|
||||||
public void onKeyUp (Widget sender, char keyCode, int modifiers) {
|
|
||||||
if (keyCode == KEY_ENTER) {
|
|
||||||
browse(searchBox.getText());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
DecoratorPanel decorator = new DecoratorPanel();
|
|
||||||
VerticalPanel vPanel = new VerticalPanel();
|
|
||||||
vPanel.add(new Label("Search"));
|
|
||||||
vPanel.add(searchBox);
|
|
||||||
decorator.add(vPanel);
|
|
||||||
return decorator;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void callBrowse(BrowsePanel panel, String id) {
|
|
||||||
panel.browse(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void browse(String id) {
|
|
||||||
pgf.browse(id, "javascript:document.callBrowse(document.browsePanel,'$ID')",
|
|
||||||
"my-identifierLink",
|
|
||||||
new RequestCallback() {
|
|
||||||
public void onResponseReceived(Request request, Response response) {
|
|
||||||
sourceView.setHTML(response.getText());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onError(Request request, java.lang.Throwable exception) {
|
|
||||||
// errorHandler.onError(e);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Widget createSourcePanel() {
|
|
||||||
sourceView = new HTML();
|
|
||||||
return sourceView;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected class CompletionOracle extends SuggestOracle {
|
|
||||||
|
|
||||||
public CompletionOracle() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void requestSuggestions(SuggestOracle.Request request, SuggestOracle.Callback callback) {
|
|
||||||
List<CompletionSuggestion> list = new ArrayList();
|
|
||||||
|
|
||||||
int index = Collections.binarySearch(identifiers, request.getQuery());
|
|
||||||
index = (index >= 0) ? index : -(index+1);
|
|
||||||
|
|
||||||
for (; index < identifiers.size(); index++) {
|
|
||||||
String id = identifiers.get(index);
|
|
||||||
|
|
||||||
if (id.startsWith(request.getQuery())) {
|
|
||||||
list.add(new CompletionSuggestion(id));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (list.size() > request.getLimit())
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
callback.onSuggestionsReady(request, new SuggestOracle.Response(list));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected static class CompletionSuggestion implements SuggestOracle.Suggestion {
|
|
||||||
private String string;
|
|
||||||
|
|
||||||
public CompletionSuggestion(String string) {
|
|
||||||
this.string = string;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDisplayString() {
|
|
||||||
return string;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getReplacementString() {
|
|
||||||
return string;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected class MySettingsListener implements PGFWrapper.SettingsListener {
|
|
||||||
|
|
||||||
private PGFWrapper pgf;
|
|
||||||
|
|
||||||
public MySettingsListener(PGFWrapper pgf) {
|
|
||||||
this.pgf = pgf;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onAvailableGrammarsChanged() { }
|
|
||||||
public void onSelectedGrammarChanged()
|
|
||||||
{
|
|
||||||
List<String> ids = new ArrayList();
|
|
||||||
|
|
||||||
for (int i = 0; i < pgf.getCategories().length(); i++) {
|
|
||||||
ids.add(pgf.getCategories().get(i));
|
|
||||||
}
|
|
||||||
for (int i = 0; i < pgf.getFunctions().length(); i++) {
|
|
||||||
ids.add(pgf.getFunctions().get(i));
|
|
||||||
}
|
|
||||||
|
|
||||||
Collections.sort(ids);
|
|
||||||
|
|
||||||
identifiers = ids;
|
|
||||||
sourceView.setText("");
|
|
||||||
searchBox.setText("");
|
|
||||||
}
|
|
||||||
public void onInputLanguageChanged() { }
|
|
||||||
public void onOutputLanguageChanged() { }
|
|
||||||
public void onStartCategoryChanged() { }
|
|
||||||
public void onSettingsError(String msg, Throwable e) { }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -15,8 +15,6 @@ public class TranslateApp implements EntryPoint {
|
|||||||
|
|
||||||
protected SuggestPanel suggestPanel;
|
protected SuggestPanel suggestPanel;
|
||||||
protected VerticalPanel outputPanel;
|
protected VerticalPanel outputPanel;
|
||||||
protected Widget translatePanel;
|
|
||||||
protected BrowsePanel browsePanel;
|
|
||||||
protected StatusPopup statusPopup;
|
protected StatusPopup statusPopup;
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -217,27 +215,12 @@ public class TranslateApp implements EntryPoint {
|
|||||||
//
|
//
|
||||||
|
|
||||||
protected Widget createUI() {
|
protected Widget createUI() {
|
||||||
translatePanel = createTranslatePanel();
|
|
||||||
browsePanel = createBrowsePanel();
|
|
||||||
|
|
||||||
VerticalPanel vPanel = new VerticalPanel();
|
VerticalPanel vPanel = new VerticalPanel();
|
||||||
|
|
||||||
HorizontalPanel hPanel = new HorizontalPanel();
|
|
||||||
hPanel.setVerticalAlignment(HorizontalPanel.ALIGN_MIDDLE);
|
|
||||||
hPanel.setStylePrimaryName("my-HeaderPanel");
|
|
||||||
|
|
||||||
Widget linksPanel = createLinksPanel(vPanel);
|
|
||||||
hPanel.add(linksPanel);
|
|
||||||
hPanel.setCellHorizontalAlignment(linksPanel,HorizontalPanel.ALIGN_LEFT);
|
|
||||||
|
|
||||||
Widget settingsPanel = createSettingsPanel();
|
|
||||||
hPanel.add(settingsPanel);
|
|
||||||
hPanel.setCellHorizontalAlignment(settingsPanel,HorizontalPanel.ALIGN_RIGHT);
|
|
||||||
|
|
||||||
vPanel.setWidth("100%");
|
vPanel.setWidth("100%");
|
||||||
vPanel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);
|
vPanel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);
|
||||||
vPanel.add(hPanel);
|
vPanel.add(createSuggestPanel());
|
||||||
vPanel.add(translatePanel);
|
vPanel.add(createSettingsPanel());
|
||||||
|
vPanel.add(createTranslationsPanel());
|
||||||
|
|
||||||
return vPanel;
|
return vPanel;
|
||||||
}
|
}
|
||||||
@@ -263,43 +246,6 @@ public class TranslateApp implements EntryPoint {
|
|||||||
return outputPanel;
|
return outputPanel;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Widget createTranslatePanel() {
|
|
||||||
VerticalPanel translatePanel = new VerticalPanel();
|
|
||||||
translatePanel.add(createSuggestPanel());
|
|
||||||
translatePanel.add(createTranslationsPanel());
|
|
||||||
return translatePanel;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected BrowsePanel createBrowsePanel() {
|
|
||||||
return new BrowsePanel(pgf);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Widget createLinksPanel(final Panel parent) {
|
|
||||||
HorizontalPanel linksPanel = new HorizontalPanel();
|
|
||||||
linksPanel.setStylePrimaryName("my-LinksPanel");
|
|
||||||
|
|
||||||
Hyperlink translateLink = new Hyperlink("Translate", null);
|
|
||||||
translateLink.addClickListener(new ClickListener() {
|
|
||||||
public void onClick(Widget sender) {
|
|
||||||
parent.remove(browsePanel);
|
|
||||||
parent.add(translatePanel);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
linksPanel.add(translateLink);
|
|
||||||
|
|
||||||
Hyperlink browseLink = new Hyperlink("Browse", null);
|
|
||||||
browseLink.addClickListener(new ClickListener() {
|
|
||||||
public void onClick(Widget sender) {
|
|
||||||
parent.remove(translatePanel);
|
|
||||||
parent.add(browsePanel);
|
|
||||||
browsePanel.onActivate();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
linksPanel.add(browseLink);
|
|
||||||
|
|
||||||
return linksPanel;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Widget createLoadingWidget () {
|
protected Widget createLoadingWidget () {
|
||||||
VerticalPanel loadingPanel = new VerticalPanel();
|
VerticalPanel loadingPanel = new VerticalPanel();
|
||||||
loadingPanel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);
|
loadingPanel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);
|
||||||
|
|||||||
@@ -20,34 +20,6 @@
|
|||||||
margin: 0 0.4em;
|
margin: 0 0.4em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.my-LinksPanel * {
|
|
||||||
margin: 0 0.1em;
|
|
||||||
}
|
|
||||||
|
|
||||||
.my-HeaderPanel {
|
|
||||||
width: 100%;
|
|
||||||
margin: 0 0.1em;
|
|
||||||
padding-top: 2px;
|
|
||||||
padding-bottom: 2px;
|
|
||||||
border-bottom-style: solid;
|
|
||||||
border-bottom-width: 1px;
|
|
||||||
border-bottom-color: rgb(122,165,214);
|
|
||||||
}
|
|
||||||
|
|
||||||
.my-BrowsePanel {
|
|
||||||
width: 100%;
|
|
||||||
margin: 1em;
|
|
||||||
border-width: 5px;
|
|
||||||
border-color: rgb(122,165,214);
|
|
||||||
}
|
|
||||||
|
|
||||||
.my-BrowseFrame {
|
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
margin: 1em;
|
|
||||||
border-style:none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.my-translations {
|
.my-translations {
|
||||||
margin-top: 1em;
|
margin-top: 1em;
|
||||||
}
|
}
|
||||||
@@ -84,10 +56,6 @@
|
|||||||
cursor:pointer;
|
cursor:pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
.my-error-title {
|
|
||||||
background: #DDDDDD;
|
|
||||||
}
|
|
||||||
|
|
||||||
.my-treeimage {
|
.my-treeimage {
|
||||||
width: 650px;
|
width: 650px;
|
||||||
height: 520px;
|
height: 520px;
|
||||||
@@ -98,17 +66,6 @@
|
|||||||
height: 300px;
|
height: 300px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.my-identifierLink:link {
|
|
||||||
text-decoration: none;
|
|
||||||
color: black;
|
|
||||||
}
|
|
||||||
|
|
||||||
.my-identifierLink:hover {
|
|
||||||
text-decoration: none;
|
|
||||||
color: black;
|
|
||||||
background-color: silver;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* [LANG=bg] { background-image: url("flags/bg.png"); }
|
* [LANG=bg] { background-image: url("flags/bg.png"); }
|
||||||
* [LANG=ca] { background-image: url("flags/catalonia.png"); }
|
* [LANG=ca] { background-image: url("flags/catalonia.png"); }
|
||||||
|
|||||||
Reference in New Issue
Block a user