mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 19:42:50 -06:00
Added first version of the fridge poetry gui
This commit is contained in:
17
src/server/gwt/Fridge-compile
Normal file
17
src/server/gwt/Fridge-compile
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
APPDIR=`dirname $0`;
|
||||||
|
|
||||||
|
if [ -z "$GWT_CLASSPATH" ]; then
|
||||||
|
echo 'ERROR: $GWT_CLASSPATH is not set'
|
||||||
|
echo 'Set $GWT_CLASSPATH to point to the GWT JAR files. For example:'
|
||||||
|
echo 'export GWT_DIR="/Users/bringert/src/gwt-mac-1.5.2"'
|
||||||
|
echo 'export GWT_CLASSPATH="$GWT_DIR/gwt-user.jar:$GWT_DIR/gwt-dev-mac.jar"'
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ `uname` = "Darwin" ]; then
|
||||||
|
GWT_JAVA_OPTS=-XstartOnFirstThread
|
||||||
|
fi
|
||||||
|
|
||||||
|
java $GWT_JAVA_OPTS -Xmx256M -cp "$APPDIR/src:$APPDIR/bin:$GWT_CLASSPATH" com.google.gwt.dev.GWTCompiler -out "$APPDIR/www" "$@" se.chalmers.cs.gf.gwt.FridgeApp;
|
||||||
17
src/server/gwt/Fridge-shell-external
Normal file
17
src/server/gwt/Fridge-shell-external
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
APPDIR=`dirname $0`;
|
||||||
|
|
||||||
|
if [ -z "$GWT_CLASSPATH" ]; then
|
||||||
|
echo 'ERROR: $GWT_CLASSPATH is not set'
|
||||||
|
echo 'Set $GWT_CLASSPATH to point to the GWT JAR files. For example:'
|
||||||
|
echo 'export GWT_DIR="/Users/bringert/src/gwt-mac-1.5.2"'
|
||||||
|
echo 'export GWT_CLASSPATH="$GWT_DIR/gwt-user.jar:$GWT_DIR/gwt-dev-mac.jar"'
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ `uname` = "Darwin" ]; then
|
||||||
|
GWT_JAVA_OPTS=-XstartOnFirstThread
|
||||||
|
fi
|
||||||
|
|
||||||
|
java $GWT_JAVA_OPTS -Xmx256M -cp "$APPDIR/src:$APPDIR/bin:$GWT_CLASSPATH" com.google.gwt.dev.GWTShell -out "$APPDIR/www" -noserver "$@" http://localhost:41296/gwt/www/se.chalmers.cs.gf.gwt.FridgeApp/Fridge.html;
|
||||||
21
src/server/gwt/FridgeApp.launch
Normal file
21
src/server/gwt/FridgeApp.launch
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
|
||||||
|
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
|
||||||
|
<listEntry value="/GF-GWT"/>
|
||||||
|
</listAttribute>
|
||||||
|
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
|
||||||
|
<listEntry value="4"/>
|
||||||
|
</listAttribute>
|
||||||
|
<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/>
|
||||||
|
<listAttribute key="org.eclipse.jdt.launching.CLASSPATH">
|
||||||
|
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry containerPath="org.eclipse.jdt.launching.JRE_CONTAINER" javaProject="GF-GWT" path="1" type="4"/> "/>
|
||||||
|
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry internalArchive="/GF-GWT/src" path="3" type="2"/> "/>
|
||||||
|
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry id="org.eclipse.jdt.launching.classpathentry.defaultClasspath"> <memento project="GF-GWT"/> </runtimeClasspathEntry> "/>
|
||||||
|
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry externalArchive="/Users/bringert/src/gwt-mac-1.5.3/gwt-dev-mac.jar" path="3" type="2"/> "/>
|
||||||
|
</listAttribute>
|
||||||
|
<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="false"/>
|
||||||
|
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="com.google.gwt.dev.GWTShell"/>
|
||||||
|
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-out www -noserver http://localhost:41296/gwt/www/se.chalmers.cs.gf.gwt.FridgeApp/Fridge.html"/>
|
||||||
|
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="GF-GWT"/>
|
||||||
|
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-XstartOnFirstThread -Xmx256M"/>
|
||||||
|
</launchConfiguration>
|
||||||
@@ -1,16 +1,21 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
|
<launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
|
||||||
<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="false"/>
|
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
|
||||||
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="com.google.gwt.dev.GWTShell"/>
|
<listEntry value="/GF-GWT"/>
|
||||||
|
</listAttribute>
|
||||||
|
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
|
||||||
|
<listEntry value="4"/>
|
||||||
|
</listAttribute>
|
||||||
|
<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/>
|
||||||
<listAttribute key="org.eclipse.jdt.launching.CLASSPATH">
|
<listAttribute key="org.eclipse.jdt.launching.CLASSPATH">
|
||||||
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry containerPath="org.eclipse.jdt.launching.JRE_CONTAINER" javaProject="GF-GWT" path="1" type="4"/> "/>
|
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry containerPath="org.eclipse.jdt.launching.JRE_CONTAINER" javaProject="GF-GWT" path="1" type="4"/> "/>
|
||||||
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry internalArchive="/GF-GWT/src" path="3" type="2"/> "/>
|
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry internalArchive="/GF-GWT/src" path="3" type="2"/> "/>
|
||||||
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry id="org.eclipse.jdt.launching.classpathentry.defaultClasspath"> <memento project="GF-GWT"/> </runtimeClasspathEntry> "/>
|
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry id="org.eclipse.jdt.launching.classpathentry.defaultClasspath"> <memento project="GF-GWT"/> </runtimeClasspathEntry> "/>
|
||||||
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry externalArchive="/Users/bringert/src/gwt-mac-1.5.3/gwt-dev-mac.jar" path="3" type="2"/> "/>
|
<listEntry value="<?xml version="1.0" encoding="UTF-8"?> <runtimeClasspathEntry externalArchive="/Users/bringert/src/gwt-mac-1.5.3/gwt-dev-mac.jar" path="3" type="2"/> "/>
|
||||||
|
|
||||||
</listAttribute>
|
</listAttribute>
|
||||||
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-XstartOnFirstThread -Xmx256M"/>
|
<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="false"/>
|
||||||
|
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="com.google.gwt.dev.GWTShell"/>
|
||||||
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-out www -noserver http://localhost:41296/gwt/www/se.chalmers.cs.gf.gwt.TranslateApp/Translate.html"/>
|
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-out www -noserver http://localhost:41296/gwt/www/se.chalmers.cs.gf.gwt.TranslateApp/Translate.html"/>
|
||||||
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="GF-GWT"/>
|
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="GF-GWT"/>
|
||||||
<booleanAttribute key="org.eclipse.debug.core.appendEnvironmentVariables" value="true"/>
|
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-XstartOnFirstThread -Xmx256M"/>
|
||||||
</launchConfiguration>
|
</launchConfiguration>
|
||||||
|
|||||||
24
src/server/gwt/src/se/chalmers/cs/gf/gwt/FridgeApp.gwt.xml
Normal file
24
src/server/gwt/src/se/chalmers/cs/gf/gwt/FridgeApp.gwt.xml
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
<module>
|
||||||
|
|
||||||
|
<!-- Inherit the core Web Toolkit stuff. -->
|
||||||
|
<inherits name="com.google.gwt.user.User" />
|
||||||
|
|
||||||
|
<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 -->
|
||||||
|
<!-- any one of the following lines. -->
|
||||||
|
<inherits name="com.google.gwt.user.theme.standard.Standard"/>
|
||||||
|
<!-- <inherits name="com.google.gwt.user.theme.chrome.Chrome"/> -->
|
||||||
|
<!-- <inherits name="com.google.gwt.user.theme.dark.Dark"/> -->
|
||||||
|
|
||||||
|
<!-- Other module inherits -->
|
||||||
|
|
||||||
|
|
||||||
|
<!-- Specify the app entry point class. -->
|
||||||
|
<entry-point class="se.chalmers.cs.gf.gwt.client.FridgeApp" />
|
||||||
|
|
||||||
|
<!-- Specify the application specific style sheet. -->
|
||||||
|
<stylesheet src="Fridge.css" />
|
||||||
|
|
||||||
|
</module>
|
||||||
235
src/server/gwt/src/se/chalmers/cs/gf/gwt/client/FridgeApp.java
Normal file
235
src/server/gwt/src/se/chalmers/cs/gf/gwt/client/FridgeApp.java
Normal file
@@ -0,0 +1,235 @@
|
|||||||
|
package se.chalmers.cs.gf.gwt.client;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.google.gwt.core.client.EntryPoint;
|
||||||
|
import com.google.gwt.user.client.ui.Button;
|
||||||
|
import com.google.gwt.user.client.ui.ClickListener;
|
||||||
|
import com.google.gwt.user.client.ui.FlowPanel;
|
||||||
|
import com.google.gwt.user.client.ui.HorizontalPanel;
|
||||||
|
import com.google.gwt.user.client.ui.Label;
|
||||||
|
import com.google.gwt.user.client.ui.Panel;
|
||||||
|
import com.google.gwt.user.client.ui.PushButton;
|
||||||
|
import com.google.gwt.user.client.ui.RootPanel;
|
||||||
|
import com.google.gwt.user.client.ui.VerticalPanel;
|
||||||
|
import com.google.gwt.user.client.ui.Widget;
|
||||||
|
|
||||||
|
|
||||||
|
public class FridgeApp implements EntryPoint {
|
||||||
|
|
||||||
|
private static final String pgfBaseURL = "/pgf";
|
||||||
|
|
||||||
|
private PGF pgf;
|
||||||
|
|
||||||
|
private FlowPanel textPanel;
|
||||||
|
private Panel bagPanel;
|
||||||
|
private SettingsPanel settingsPanel;
|
||||||
|
private VerticalPanel outputPanel;
|
||||||
|
private StatusPopup statusPopup;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Translation
|
||||||
|
//
|
||||||
|
|
||||||
|
private void translate() {
|
||||||
|
outputPanel.clear();
|
||||||
|
setStatus("Translating...");
|
||||||
|
pgf.translate(settingsPanel.getGrammarName(),
|
||||||
|
getText(),
|
||||||
|
settingsPanel.getInputLanguages(), null,
|
||||||
|
settingsPanel.getOutputLanguages(),
|
||||||
|
new PGF.TranslateCallback() {
|
||||||
|
public void onResult (PGF.Translations translations) {
|
||||||
|
for (final PGF.Translation t : translations.iterable()) {
|
||||||
|
PushButton l = new PushButton(t.getText());
|
||||||
|
l.addStyleName("my-translation");
|
||||||
|
l.addClickListener(new ClickListener() {
|
||||||
|
public void onClick(Widget sender) {
|
||||||
|
setText(t.getTo(), t.getText());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
PGF.Language lang = settingsPanel.getGrammar().getLanguage(t.getTo());
|
||||||
|
if (lang != null) {
|
||||||
|
l.getElement().setLang(lang.getLanguageCode());
|
||||||
|
}
|
||||||
|
outputPanel.add(l);
|
||||||
|
}
|
||||||
|
clearStatus();
|
||||||
|
}
|
||||||
|
public void onError (Throwable e) {
|
||||||
|
showError("Translation failed", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Magnets
|
||||||
|
//
|
||||||
|
|
||||||
|
private List<String> getWords() {
|
||||||
|
List<String> l = new ArrayList<String>();
|
||||||
|
for (Widget w : textPanel) {
|
||||||
|
l.add(((Magnet)w).getText());
|
||||||
|
}
|
||||||
|
return l;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getText () {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (String word : getWords()) {
|
||||||
|
if (sb.length() > 0) {
|
||||||
|
sb.append(' ');
|
||||||
|
}
|
||||||
|
sb.append(word);
|
||||||
|
}
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setText (String language, String text) {
|
||||||
|
settingsPanel.setInputLanguages(Collections.singletonList(language));
|
||||||
|
textPanel.clear();
|
||||||
|
for (String word : text.split("\\s+")) {
|
||||||
|
textPanel.add(new Magnet(language, word));
|
||||||
|
}
|
||||||
|
updateBag();
|
||||||
|
}
|
||||||
|
|
||||||
|
private ClickListener magnetClickListener = new ClickListener () {
|
||||||
|
public void onClick(Widget sender) {
|
||||||
|
Magnet magnet = (Magnet)sender;
|
||||||
|
textPanel.add(new Magnet(magnet));
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private void updateBag () {
|
||||||
|
bagPanel.clear();
|
||||||
|
int limit = 100;
|
||||||
|
pgf.complete(settingsPanel.getGrammarName(),
|
||||||
|
getText() + " ",
|
||||||
|
settingsPanel.getInputLanguages(), null,
|
||||||
|
limit, new PGF.CompleteCallback() {
|
||||||
|
public void onResult(PGF.Completions completions) {
|
||||||
|
boolean empty = true;
|
||||||
|
List<String> oldWords = getWords();
|
||||||
|
for (PGF.Completion completion : completions.iterable()) {
|
||||||
|
String[] newWords = completion.getText().split("\\s+");
|
||||||
|
if (newWords.length == oldWords.size()+1) {
|
||||||
|
String word = newWords[newWords.length-1];
|
||||||
|
bagPanel.add(new Magnet(completion.getFrom(), word, magnetClickListener));
|
||||||
|
empty = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (empty) {
|
||||||
|
bagPanel.add(new Label("<empty>"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public void onError(Throwable e) {
|
||||||
|
showError("Error getting completions.", e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update() {
|
||||||
|
updateBag();
|
||||||
|
translate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear() {
|
||||||
|
textPanel.clear();
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteLastMagnet() {
|
||||||
|
int c = textPanel.getWidgetCount();
|
||||||
|
if (c > 0) {
|
||||||
|
textPanel.remove(c-1);
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Status stuff
|
||||||
|
//
|
||||||
|
|
||||||
|
private void setStatus(String msg) {
|
||||||
|
statusPopup.setStatus(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showError(String msg, Throwable e) {
|
||||||
|
statusPopup.showError(msg, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void clearStatus() {
|
||||||
|
statusPopup.clearStatus();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// GUI
|
||||||
|
//
|
||||||
|
|
||||||
|
private void createTranslationUI() {
|
||||||
|
|
||||||
|
statusPopup = new StatusPopup();
|
||||||
|
setStatus("Loading...");
|
||||||
|
|
||||||
|
settingsPanel = new SettingsPanel(pgf);
|
||||||
|
settingsPanel.addSettingsListener(new SettingsPanel.SettingsListener() {
|
||||||
|
public void grammarChanged(String pgfName) {
|
||||||
|
}
|
||||||
|
public void languagesChanged(List<String> inputLangs, List<String> outputLangs) {
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
public void settingsError(String msg, Throwable e) {
|
||||||
|
showError(msg,e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Panel buttons = new HorizontalPanel();
|
||||||
|
buttons.add(new Button("Clear", new ClickListener () {
|
||||||
|
public void onClick(Widget sender) {
|
||||||
|
clear();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
buttons.add(new Button("Delete last", new ClickListener () {
|
||||||
|
public void onClick(Widget sender) {
|
||||||
|
deleteLastMagnet();
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
outputPanel = new VerticalPanel();
|
||||||
|
outputPanel.addStyleName("my-translations");
|
||||||
|
|
||||||
|
textPanel = new FlowPanel();
|
||||||
|
textPanel.setStylePrimaryName("my-TextPanel");
|
||||||
|
|
||||||
|
bagPanel = new FlowPanel();
|
||||||
|
bagPanel.setStylePrimaryName("my-BagPanel");
|
||||||
|
|
||||||
|
VerticalPanel mainPanel = new VerticalPanel();
|
||||||
|
mainPanel.setHorizontalAlignment(VerticalPanel.ALIGN_CENTER);
|
||||||
|
mainPanel.setWidth("100%");
|
||||||
|
mainPanel.add(textPanel);
|
||||||
|
mainPanel.add(buttons);
|
||||||
|
mainPanel.add(bagPanel);
|
||||||
|
mainPanel.add(outputPanel);
|
||||||
|
mainPanel.add(settingsPanel);
|
||||||
|
|
||||||
|
RootPanel.get().add(mainPanel);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// Initialization
|
||||||
|
//
|
||||||
|
|
||||||
|
public void onModuleLoad() {
|
||||||
|
pgf = new PGF(pgfBaseURL);
|
||||||
|
createTranslationUI();
|
||||||
|
settingsPanel.updateAvailableGrammars();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
66
src/server/gwt/src/se/chalmers/cs/gf/gwt/client/Magnet.java
Normal file
66
src/server/gwt/src/se/chalmers/cs/gf/gwt/client/Magnet.java
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
package se.chalmers.cs.gf.gwt.client;
|
||||||
|
|
||||||
|
import com.google.gwt.user.client.ui.ClickListener;
|
||||||
|
import com.google.gwt.user.client.ui.ClickListenerCollection;
|
||||||
|
import com.google.gwt.user.client.ui.Composite;
|
||||||
|
import com.google.gwt.user.client.ui.PushButton;
|
||||||
|
import com.google.gwt.user.client.ui.SourcesClickEvents;
|
||||||
|
import com.google.gwt.user.client.ui.Widget;
|
||||||
|
|
||||||
|
public class Magnet extends Composite implements SourcesClickEvents {
|
||||||
|
|
||||||
|
private String language;
|
||||||
|
|
||||||
|
private String text;
|
||||||
|
|
||||||
|
private ClickListenerCollection clickListeners = null;
|
||||||
|
|
||||||
|
public Magnet(Magnet magnet) {
|
||||||
|
this(magnet.language, magnet.text);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Magnet(String language, String text) {
|
||||||
|
this(language, text, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Magnet(String language, String text, ClickListener listener) {
|
||||||
|
this.language = language;
|
||||||
|
this.text = text;
|
||||||
|
final PushButton button = new PushButton(text);
|
||||||
|
button.addClickListener(new ClickListener() {
|
||||||
|
public void onClick(Widget sender) {
|
||||||
|
button.setFocus(false);
|
||||||
|
fireClick();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
initWidget(button);
|
||||||
|
addStyleName("my-Magnet");
|
||||||
|
if (listener != null) {
|
||||||
|
addClickListener(listener);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getText() {
|
||||||
|
return text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addClickListener(ClickListener listener) {
|
||||||
|
if (clickListeners == null) {
|
||||||
|
clickListeners = new ClickListenerCollection();
|
||||||
|
}
|
||||||
|
clickListeners.add(listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeClickListener(ClickListener listener) {
|
||||||
|
if (clickListeners != null) {
|
||||||
|
clickListeners.remove(listener);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void fireClick () {
|
||||||
|
if (clickListeners != null) {
|
||||||
|
clickListeners.fireClick(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,24 +1,34 @@
|
|||||||
package se.chalmers.cs.gf.gwt.client;
|
package se.chalmers.cs.gf.gwt.client;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import com.google.gwt.user.client.ui.ListBox;
|
import com.google.gwt.user.client.ui.ListBox;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class MultiListBox extends ListBox {
|
public class MultiListBox extends ListBox {
|
||||||
|
|
||||||
public MultiListBox() {
|
public MultiListBox() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getSelectedValues() {
|
public List<String> getSelectedValues() {
|
||||||
int c = getItemCount();
|
int c = getItemCount();
|
||||||
List<String> l = new ArrayList<String>();
|
List<String> l = new ArrayList<String>();
|
||||||
for (int i = 0; i < c; i++) {
|
for (int i = 0; i < c; i++) {
|
||||||
if (isItemSelected(i)) {
|
if (isItemSelected(i)) {
|
||||||
l.add(getValue(i));
|
l.add(getValue(i));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return l;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSelectedValues(List<String> values) {
|
||||||
|
Set<String> vs = new HashSet<String>(values);
|
||||||
|
int c = getItemCount();
|
||||||
|
for (int i = 0; i < c; i++) {
|
||||||
|
setItemSelected(i, vs.contains(getValue(i)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return l;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -105,6 +105,11 @@ public class PGF {
|
|||||||
|
|
||||||
/* Completion */
|
/* Completion */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get suggestions for completing the input.
|
||||||
|
* @param limit The number of suggestions to get.
|
||||||
|
* If -1 is passed, all available suggestions are retrieved.
|
||||||
|
*/
|
||||||
public JSONRequest complete (String pgfName, String input, List<String> fromLangs, String cat, int limit, final CompleteCallback callback) {
|
public JSONRequest complete (String pgfName, 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));
|
||||||
@@ -114,7 +119,9 @@ public class PGF {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
args.add(new Arg("cat", cat));
|
args.add(new Arg("cat", cat));
|
||||||
args.add(new Arg("limit", limit));
|
if (limit != -1) {
|
||||||
|
args.add(new Arg("limit", limit));
|
||||||
|
}
|
||||||
return sendGrammarRequest(pgfName, "complete", args, callback);
|
return sendGrammarRequest(pgfName, "complete", args, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -121,12 +121,16 @@ public class SettingsPanel extends Composite {
|
|||||||
|
|
||||||
public List<String> getInputLanguages() {
|
public List<String> getInputLanguages() {
|
||||||
return fromLangBox.getSelectedValues();
|
return fromLangBox.getSelectedValues();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getOutputLanguages() {
|
public List<String> getOutputLanguages() {
|
||||||
return toLangBox.getSelectedValues();
|
return toLangBox.getSelectedValues();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setInputLanguages(List<String> langs) {
|
||||||
|
fromLangBox.setSelectedValues(langs);
|
||||||
|
}
|
||||||
|
|
||||||
private void updateAvailableLanguages() {
|
private void updateAvailableLanguages() {
|
||||||
pgf.grammar(getGrammarName(), new PGF.GrammarCallback() {
|
pgf.grammar(getGrammarName(), new PGF.GrammarCallback() {
|
||||||
public void onResult(PGF.Grammar grammar) {
|
public void onResult(PGF.Grammar grammar) {
|
||||||
|
|||||||
32
src/server/gwt/src/se/chalmers/cs/gf/gwt/public/Fridge.css
Normal file
32
src/server/gwt/src/se/chalmers/cs/gf/gwt/public/Fridge.css
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
.my-TextPanel, .my-BagPanel, .my-translations, .my-SettingsPanel {
|
||||||
|
margin: 1em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.my-TextPanel {
|
||||||
|
font-size: 150%;
|
||||||
|
min-height: 2em;
|
||||||
|
border: 3px dashed silver;
|
||||||
|
overflow: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.my-BagPanel {
|
||||||
|
border: 1px solid silver;
|
||||||
|
overflow: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.my-Magnet {
|
||||||
|
float: left;
|
||||||
|
margin: 0.3em;
|
||||||
|
padding: 0.3em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.my-translations {
|
||||||
|
border: 1px solid silver;
|
||||||
|
}
|
||||||
|
|
||||||
|
.my-translation {
|
||||||
|
margin: 0.2em;
|
||||||
|
}
|
||||||
|
|
||||||
|
.my-SettingsPanel {
|
||||||
|
}
|
||||||
36
src/server/gwt/src/se/chalmers/cs/gf/gwt/public/Fridge.html
Normal file
36
src/server/gwt/src/se/chalmers/cs/gf/gwt/public/Fridge.html
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||||
|
<!-- The HTML 4.01 Transitional DOCTYPE declaration-->
|
||||||
|
<!-- above set at the top of the file will set -->
|
||||||
|
<!-- the browser's rendering engine into -->
|
||||||
|
<!-- "Quirks Mode". Replacing this declaration -->
|
||||||
|
<!-- with a "Standards Mode" doctype is supported, -->
|
||||||
|
<!-- but may lead to some differences in layout. -->
|
||||||
|
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||||
|
<!-- -->
|
||||||
|
<!-- Any title is fine -->
|
||||||
|
<!-- -->
|
||||||
|
<title>Fridge</title>
|
||||||
|
|
||||||
|
<!-- -->
|
||||||
|
<!-- This script loads your compiled module. -->
|
||||||
|
<!-- If you add any GWT meta tags, they must -->
|
||||||
|
<!-- be added before this line. -->
|
||||||
|
<!-- -->
|
||||||
|
<script type="text/javascript" language="javascript" src="se.chalmers.cs.gf.gwt.FridgeApp.nocache.js"></script>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<!-- -->
|
||||||
|
<!-- The body can have arbitrary html, or -->
|
||||||
|
<!-- you can leave the body empty if you want -->
|
||||||
|
<!-- to create a completely dynamic UI. -->
|
||||||
|
<!-- -->
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<!-- OPTIONAL: include this if you want history support -->
|
||||||
|
<iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user