forked from GitHub/gf-core
added tree visualizations in TranslateApp
This commit is contained in:
@@ -2,7 +2,8 @@
|
|||||||
module FastCGIUtils (initFastCGI, loopFastCGI,
|
module FastCGIUtils (initFastCGI, loopFastCGI,
|
||||||
throwCGIError, handleCGIErrors,
|
throwCGIError, handleCGIErrors,
|
||||||
stderrToFile,
|
stderrToFile,
|
||||||
outputJSONP,
|
outputJSONP,
|
||||||
|
outputPNG,
|
||||||
splitBy) where
|
splitBy) where
|
||||||
|
|
||||||
import Control.Concurrent
|
import Control.Concurrent
|
||||||
@@ -164,6 +165,11 @@ outputJSONP x =
|
|||||||
setHeader "Content-Type" "text/json; charset=utf-8"
|
setHeader "Content-Type" "text/json; charset=utf-8"
|
||||||
outputStrict $ UTF8.encodeString str
|
outputStrict $ UTF8.encodeString str
|
||||||
|
|
||||||
|
outputPNG :: String -> CGI CGIResult
|
||||||
|
outputPNG x = do
|
||||||
|
setHeader "Content-Type" "image/png"
|
||||||
|
outputStrict x
|
||||||
|
|
||||||
outputStrict :: String -> CGI CGIResult
|
outputStrict :: String -> CGI CGIResult
|
||||||
outputStrict x | x == x = output x
|
outputStrict x | x == x = output x
|
||||||
| otherwise = fail "I am the pope."
|
| otherwise = fail "I am the pope."
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import qualified Data.Map as Map
|
|||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
import System.Directory
|
import System.Directory
|
||||||
import System.FilePath
|
import System.FilePath
|
||||||
|
import System.Process
|
||||||
|
|
||||||
logFile :: FilePath
|
logFile :: FilePath
|
||||||
logFile = "pgf-error.log"
|
logFile = "pgf-error.log"
|
||||||
@@ -37,18 +38,20 @@ cgiMain cache =
|
|||||||
do path <- getVarWithDefault "SCRIPT_FILENAME" ""
|
do path <- getVarWithDefault "SCRIPT_FILENAME" ""
|
||||||
pgf <- liftIO $ readCache cache path
|
pgf <- liftIO $ readCache cache path
|
||||||
command <- liftM (maybe "grammar" (urlDecodeUnicode . UTF8.decodeString)) (getInput "command")
|
command <- liftM (maybe "grammar" (urlDecodeUnicode . UTF8.decodeString)) (getInput "command")
|
||||||
jsonp <- pgfMain pgf command
|
pgfMain pgf command
|
||||||
outputJSONP jsonp
|
|
||||||
|
|
||||||
pgfMain :: PGF -> String -> CGI JSValue
|
pgfMain :: PGF -> String -> CGI CGIResult
|
||||||
pgfMain pgf command =
|
pgfMain pgf command =
|
||||||
case command of
|
case command of
|
||||||
"parse" -> return (doParse pgf) `ap` getText `ap` getCat `ap` getFrom
|
"parse" -> return (doParse pgf) `ap` getText `ap` getCat `ap` getFrom >>= outputJSONP
|
||||||
"complete" -> return (doComplete pgf) `ap` getText `ap` getCat `ap` getFrom `ap` getLimit
|
"complete" -> return (doComplete pgf) `ap` getText `ap` getCat `ap` getFrom `ap` getLimit >>= outputJSONP
|
||||||
"linearize" -> return (doLinearize pgf) `ap` getTree `ap` getTo
|
"linearize" -> return (doLinearize pgf) `ap` getTree `ap` getTo >>= outputJSONP
|
||||||
"random" -> getCat >>= \c -> getLimit >>= liftIO . doRandom pgf c
|
"random" -> getCat >>= \c -> getLimit >>= liftIO . doRandom pgf c >>= outputJSONP
|
||||||
"translate" -> return (doTranslate pgf) `ap` getText `ap` getCat `ap` getFrom `ap` getTo
|
"translate" -> return (doTranslate pgf) `ap` getText `ap` getCat `ap` getFrom `ap` getTo >>= outputJSONP
|
||||||
"grammar" -> return (doGrammar pgf) `ap` requestAcceptLanguage
|
"grammar" -> return (doGrammar pgf) `ap` requestAcceptLanguage >>= outputJSONP
|
||||||
|
"abstrtree" -> getTree >>= liftIO . doGraphvizAbstrTree pgf >>= outputPNG
|
||||||
|
"parsetree" -> getTree >>= \t -> getFrom >>= \(Just l) -> liftIO (doGraphvizParseTree pgf l t) >>= outputPNG
|
||||||
|
"alignment" -> getTree >>= liftIO . doGraphvizAlignment pgf >>= outputPNG
|
||||||
_ -> throwCGIError 400 "Unknown command" ["Unknown command: " ++ show command]
|
_ -> throwCGIError 400 "Unknown command" ["Unknown command: " ++ show command]
|
||||||
where
|
where
|
||||||
getText :: CGI String
|
getText :: CGI String
|
||||||
@@ -68,7 +71,7 @@ pgfMain pgf command =
|
|||||||
Just cat -> case PGF.readType cat of
|
Just cat -> case PGF.readType cat of
|
||||||
Nothing -> throwCGIError 400 "Bad category" ["Bad category: " ++ cat]
|
Nothing -> throwCGIError 400 "Bad category" ["Bad category: " ++ cat]
|
||||||
Just typ | typ `elem` PGF.categories pgf -> return $ Just typ
|
Just typ | typ `elem` PGF.categories pgf -> return $ Just typ
|
||||||
| otherwise -> throwCGIError 400 "Unknown category" ["Unknown category: " ++ show typ]
|
| otherwise -> throwCGIError 400 "Unknown category" ["Unknown category: " ++ PGF.showType [] typ]
|
||||||
|
|
||||||
getFrom :: CGI (Maybe PGF.Language)
|
getFrom :: CGI (Maybe PGF.Language)
|
||||||
getFrom = getLang "from"
|
getFrom = getLang "from"
|
||||||
@@ -98,11 +101,15 @@ doListGrammars =
|
|||||||
return $ showJSON $ map toJSObject [[("name", f)] | f <- fs]
|
return $ showJSON $ map toJSObject [[("name", f)] | f <- fs]
|
||||||
|
|
||||||
doTranslate :: PGF -> String -> Maybe PGF.Type -> Maybe PGF.Language -> Maybe PGF.Language -> JSValue
|
doTranslate :: PGF -> String -> Maybe PGF.Type -> Maybe PGF.Language -> Maybe PGF.Language -> JSValue
|
||||||
doTranslate pgf input mcat mfrom mto = showJSON $ map toJSObject
|
doTranslate pgf input mcat mfrom mto =
|
||||||
[[("from", PGF.showLanguage from),("to", PGF.showLanguage to),("text",output)]
|
showJSON
|
||||||
|
[toJSObject [("from", showJSON (PGF.showLanguage from)),
|
||||||
|
("tree", showJSON tree),
|
||||||
|
("linearizations",showJSON [toJSObject [("to", PGF.showLanguage to),("text",output)]
|
||||||
|
| (to,output) <- linearize' pgf mto tree])
|
||||||
|
]
|
||||||
| (from,trees) <- parse' pgf input mcat mfrom,
|
| (from,trees) <- parse' pgf input mcat mfrom,
|
||||||
tree <- trees,
|
tree <- trees]
|
||||||
(to,output) <- linearize' pgf mto tree]
|
|
||||||
|
|
||||||
doParse :: PGF -> String -> Maybe PGF.Type -> Maybe PGF.Language -> JSValue
|
doParse :: PGF -> String -> Maybe PGF.Type -> Maybe PGF.Language -> JSValue
|
||||||
doParse pgf input mcat mfrom = showJSON $ map toJSObject
|
doParse pgf input mcat mfrom = showJSON $ map toJSObject
|
||||||
@@ -141,10 +148,26 @@ doGrammar pgf macc = showJSON $ toJSObject
|
|||||||
| l <- PGF.languages pgf]
|
| l <- PGF.languages pgf]
|
||||||
categories = map toJSObject [[("cat", PGF.showType [] cat)] | cat <- PGF.categories pgf]
|
categories = map toJSObject [[("cat", PGF.showType [] cat)] | cat <- PGF.categories pgf]
|
||||||
|
|
||||||
|
doGraphvizAbstrTree pgf tree = do
|
||||||
|
let dot = PGF.graphvizAbstractTree pgf (True,True) tree
|
||||||
|
readProcess "dot" ["-T","png"] dot
|
||||||
|
|
||||||
|
doGraphvizParseTree pgf lang tree = do
|
||||||
|
let dot = PGF.graphvizParseTree pgf lang tree
|
||||||
|
readProcess "dot" ["-T","png"] (UTF8.encodeString dot)
|
||||||
|
|
||||||
|
doGraphvizAlignment pgf tree = do
|
||||||
|
let dot = PGF.graphvizAlignment pgf tree
|
||||||
|
readProcess "dot" ["-T","png"] (UTF8.encodeString dot)
|
||||||
|
|
||||||
instance JSON PGF.CId where
|
instance JSON PGF.CId where
|
||||||
readJSON x = readJSON x >>= maybe (fail "Bad language.") return . PGF.readLanguage
|
readJSON x = readJSON x >>= maybe (fail "Bad language.") return . PGF.readLanguage
|
||||||
showJSON = showJSON . PGF.showLanguage
|
showJSON = showJSON . PGF.showLanguage
|
||||||
|
|
||||||
|
instance JSON PGF.Expr where
|
||||||
|
readJSON x = readJSON x >>= maybe (fail "Bad expression.") return . PGF.readExpr
|
||||||
|
showJSON = showJSON . PGF.showExpr []
|
||||||
|
|
||||||
-- * PGF utilities
|
-- * PGF utilities
|
||||||
|
|
||||||
cat :: PGF -> Maybe PGF.Type -> PGF.Type
|
cat :: PGF -> Maybe PGF.Type -> PGF.Type
|
||||||
|
|||||||
@@ -58,7 +58,9 @@ public class FridgeApp implements EntryPoint {
|
|||||||
public void onResult (PGF.Translations translations) {
|
public void onResult (PGF.Translations translations) {
|
||||||
outputPanel.removeStyleDependentName("working");
|
outputPanel.removeStyleDependentName("working");
|
||||||
for (PGF.Translation t : translations.iterable()) {
|
for (PGF.Translation t : translations.iterable()) {
|
||||||
outputPanel.add(createTranslation(t.getTo(), t.getText()));
|
for (PGF.Linearization l : t.getLinearizations().iterable()) {
|
||||||
|
outputPanel.add(createTranslation(l.getTo(), l.getText()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void onError (Throwable e) {
|
public void onError (Throwable e) {
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ public class JSONRequestBuilder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static <T extends JavaScriptObject> JSONRequest sendRequest (String base, List<Arg> vars, final JSONCallback<T> callback) {
|
public static <T extends JavaScriptObject> JSONRequest sendRequest (String base, List<Arg> vars, final JSONCallback<T> callback) {
|
||||||
String url = base + "?" + buildQueryString(vars);
|
String url = getQueryURL(base,vars);
|
||||||
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
|
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
|
||||||
builder.setTimeoutMillis(30000);
|
builder.setTimeoutMillis(30000);
|
||||||
builder.setHeader("Accept","text/plain, text/html;q=0.5, */*;q=0.1");
|
builder.setHeader("Accept","text/plain, text/html;q=0.5, */*;q=0.1");
|
||||||
@@ -57,8 +57,10 @@ public class JSONRequestBuilder {
|
|||||||
return eval('(' + json + ')');
|
return eval('(' + json + ')');
|
||||||
}-*/;
|
}-*/;
|
||||||
|
|
||||||
private static String buildQueryString(List<Arg> args) {
|
public static String getQueryURL(String base, List<Arg> args) {
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
|
sb.append(base);
|
||||||
|
sb.append("?");
|
||||||
if (args != null) {
|
if (args != null) {
|
||||||
for (Arg arg : args) {
|
for (Arg arg : args) {
|
||||||
if (arg.value != null) {
|
if (arg.value != null) {
|
||||||
|
|||||||
@@ -60,8 +60,19 @@ public class PGF {
|
|||||||
protected Translation() { }
|
protected Translation() { }
|
||||||
|
|
||||||
public final native String getFrom() /*-{ return this.from; }-*/;
|
public final native String getFrom() /*-{ return this.from; }-*/;
|
||||||
|
public final native String getTree() /*-{ return this.tree; }-*/;
|
||||||
|
public final native Linearizations getLinearizations() /*-{ return this.linearizations; }-*/;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Linearizations extends IterableJsArray<Linearization> {
|
||||||
|
protected Linearizations() { }
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Linearization extends JavaScriptObject {
|
||||||
|
protected Linearization() { }
|
||||||
|
|
||||||
public final native String getTo() /*-{ return this.to; }-*/;
|
public final native String getTo() /*-{ return this.to; }-*/;
|
||||||
public final native String getText() /*-{ return this.text; }-*/;
|
public final native String getText() /*-{ return this.text; }-*/;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Completion */
|
/* Completion */
|
||||||
@@ -118,6 +129,28 @@ public class PGF {
|
|||||||
public final native String getTree() /*-{ return this.tree; }-*/;
|
public final native String getTree() /*-{ return this.tree; }-*/;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String graphvizAbstractTree(String pgfURL, String abstractTree) {
|
||||||
|
List<Arg> args = new ArrayList<Arg>();
|
||||||
|
args.add(new Arg("command", "abstrtree"));
|
||||||
|
args.add(new Arg("tree", abstractTree));
|
||||||
|
return JSONRequestBuilder.getQueryURL(pgfURL,args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String graphvizParseTree(String pgfURL, String abstractTree, String lang) {
|
||||||
|
List<Arg> args = new ArrayList<Arg>();
|
||||||
|
args.add(new Arg("command", "parsetree"));
|
||||||
|
args.add(new Arg("tree", abstractTree));
|
||||||
|
args.add(new Arg("from", lang));
|
||||||
|
return JSONRequestBuilder.getQueryURL(pgfURL,args);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String graphvizAlignment(String pgfURL, String abstractTree) {
|
||||||
|
List<Arg> args = new ArrayList<Arg>();
|
||||||
|
args.add(new Arg("command", "alignment"));
|
||||||
|
args.add(new Arg("tree", abstractTree));
|
||||||
|
return JSONRequestBuilder.getQueryURL(pgfURL,args);
|
||||||
|
}
|
||||||
|
|
||||||
/* Common */
|
/* Common */
|
||||||
|
|
||||||
public <T extends JavaScriptObject> JSONRequest sendGrammarRequest(String pgfURL, String resource, List<Arg> args, final JSONCallback<T> callback) {
|
public <T extends JavaScriptObject> JSONRequest sendGrammarRequest(String pgfURL, String resource, List<Arg> args, final JSONCallback<T> callback) {
|
||||||
|
|||||||
@@ -12,10 +12,12 @@ public class PGFWrapper {
|
|||||||
|
|
||||||
private String baseURL;
|
private String baseURL;
|
||||||
|
|
||||||
private PGF pgf;
|
private String grammarURL;
|
||||||
|
|
||||||
private String pgfName = null;
|
private String pgfName = null;
|
||||||
|
|
||||||
|
private PGF pgf;
|
||||||
|
|
||||||
private String inputLanguage = null;
|
private String inputLanguage = null;
|
||||||
|
|
||||||
private String outputLanguage = null;
|
private String outputLanguage = null;
|
||||||
@@ -39,6 +41,10 @@ public class PGFWrapper {
|
|||||||
private List<SettingsListener> listeners = new LinkedList<SettingsListener>();
|
private List<SettingsListener> listeners = new LinkedList<SettingsListener>();
|
||||||
|
|
||||||
|
|
||||||
|
public PGFWrapper() {
|
||||||
|
this.baseURL = null;
|
||||||
|
this.pgf = new PGF();
|
||||||
|
}
|
||||||
|
|
||||||
public PGFWrapper(String baseURL) {
|
public PGFWrapper(String baseURL) {
|
||||||
this.baseURL = baseURL;
|
this.baseURL = baseURL;
|
||||||
@@ -93,7 +99,7 @@ public class PGFWrapper {
|
|||||||
|
|
||||||
protected void updateSelectedGrammar () {
|
protected void updateSelectedGrammar () {
|
||||||
clearCachedInfo();
|
clearCachedInfo();
|
||||||
pgf.grammar(baseURL+"/"+pgfName, new PGF.GrammarCallback() {
|
pgf.grammar(grammarURL, new PGF.GrammarCallback() {
|
||||||
public void onResult(PGF.Grammar grammar) {
|
public void onResult(PGF.Grammar grammar) {
|
||||||
userLanguage = grammar.getUserLanguage();
|
userLanguage = grammar.getUserLanguage();
|
||||||
languages = new LinkedHashMap<String,PGF.Language>();
|
languages = new LinkedHashMap<String,PGF.Language>();
|
||||||
@@ -119,15 +125,27 @@ public class PGFWrapper {
|
|||||||
//
|
//
|
||||||
|
|
||||||
public JSONRequest translate (String input, final PGF.TranslateCallback callback) {
|
public JSONRequest translate (String input, final PGF.TranslateCallback callback) {
|
||||||
return pgf.translate(baseURL+"/"+pgfName, input, inputLanguage, cat, outputLanguage, callback);
|
return pgf.translate(grammarURL, input, inputLanguage, cat, outputLanguage, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public JSONRequest complete (String input, int limit, final PGF.CompleteCallback callback) {
|
public JSONRequest complete (String input, int limit, final PGF.CompleteCallback callback) {
|
||||||
return pgf.complete(baseURL+"/"+pgfName, input, inputLanguage, cat, limit, callback);
|
return pgf.complete(grammarURL, input, inputLanguage, cat, limit, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public JSONRequest parse (String input, final PGF.ParseCallback callback) {
|
public JSONRequest parse (String input, final PGF.ParseCallback callback) {
|
||||||
return pgf.parse(baseURL+"/"+pgfName, input, inputLanguage, cat, callback);
|
return pgf.parse(grammarURL, input, inputLanguage, cat, callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String graphvizAbstractTree(String abstractTree) {
|
||||||
|
return pgf.graphvizAbstractTree(grammarURL,abstractTree);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String graphvizParseTree(String abstractTree, String lang) {
|
||||||
|
return pgf.graphvizParseTree(grammarURL,abstractTree,lang);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String graphvizAlignment(String abstractTree) {
|
||||||
|
return pgf.graphvizAlignment(grammarURL,abstractTree);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -140,6 +158,20 @@ public class PGFWrapper {
|
|||||||
|
|
||||||
public void setPGFName(String pgfName) {
|
public void setPGFName(String pgfName) {
|
||||||
this.pgfName = pgfName;
|
this.pgfName = pgfName;
|
||||||
|
this.grammarURL = baseURL + "/" + pgfName;
|
||||||
|
this.inputLanguage = null;
|
||||||
|
this.outputLanguage = null;
|
||||||
|
this.cat = null;
|
||||||
|
updateSelectedGrammar();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGrammarURL() {
|
||||||
|
return grammarURL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGrammarURL(String grammarURL) {
|
||||||
|
this.pgfName = null;
|
||||||
|
this.grammarURL = grammarURL;
|
||||||
this.inputLanguage = null;
|
this.inputLanguage = null;
|
||||||
this.outputLanguage = null;
|
this.outputLanguage = null;
|
||||||
this.cat = null;
|
this.cat = null;
|
||||||
|
|||||||
@@ -6,10 +6,7 @@ import com.google.gwt.core.client.EntryPoint;
|
|||||||
import com.google.gwt.core.client.GWT;
|
import com.google.gwt.core.client.GWT;
|
||||||
import com.google.gwt.user.client.History;
|
import com.google.gwt.user.client.History;
|
||||||
import com.google.gwt.user.client.HistoryListener;
|
import com.google.gwt.user.client.HistoryListener;
|
||||||
import com.google.gwt.user.client.ui.Label;
|
import com.google.gwt.user.client.ui.*;
|
||||||
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 TranslateApp implements EntryPoint {
|
public class TranslateApp implements EntryPoint {
|
||||||
@@ -47,7 +44,24 @@ public class TranslateApp implements EntryPoint {
|
|||||||
outputPanel.clear();
|
outputPanel.clear();
|
||||||
outputPanel.removeStyleDependentName("working");
|
outputPanel.removeStyleDependentName("working");
|
||||||
for (PGF.Translation t : translations.iterable()) {
|
for (PGF.Translation t : translations.iterable()) {
|
||||||
outputPanel.add(createTranslation(t.getTo(), t.getText()));
|
HorizontalPanel hPanel = new HorizontalPanel();
|
||||||
|
hPanel.addStyleName("my-translation-frame");
|
||||||
|
VerticalPanel linsPanel = new VerticalPanel();
|
||||||
|
linsPanel.addStyleName("my-translation-bar");
|
||||||
|
hPanel.add(linsPanel);
|
||||||
|
HorizontalPanel btnPanel = new HorizontalPanel();
|
||||||
|
btnPanel.addStyleName("my-translation-btns");
|
||||||
|
btnPanel.setSpacing(4);
|
||||||
|
btnPanel.add(createAbsTreeButton(t.getTree()));
|
||||||
|
btnPanel.add(createAlignButton(t.getTree()));
|
||||||
|
hPanel.add(btnPanel);
|
||||||
|
hPanel.setCellHorizontalAlignment(btnPanel,
|
||||||
|
HasHorizontalAlignment.ALIGN_RIGHT);
|
||||||
|
outputPanel.add(hPanel);
|
||||||
|
|
||||||
|
for (PGF.Linearization l : t.getLinearizations().iterable()) {
|
||||||
|
linsPanel.add(createTranslation(l.getTo(), t.getTree(), l.getText()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public void onError (Throwable e) {
|
public void onError (Throwable e) {
|
||||||
@@ -56,13 +70,113 @@ public class TranslateApp implements EntryPoint {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Widget createTranslation(String language, String text) {
|
protected Widget createAbsTreeButton(final String abstractTree) {
|
||||||
|
Image treeBtn = new Image("se.chalmers.cs.gf.gwt.TranslateApp/tree-btn.png");
|
||||||
|
treeBtn.addClickListener(
|
||||||
|
new ClickListener() {
|
||||||
|
public void onClick(Widget sender) {
|
||||||
|
// Create a dialog box and set the caption text
|
||||||
|
final DialogBox dialogBox = new DialogBox();
|
||||||
|
dialogBox.setText("Abstract Syntax Tree");
|
||||||
|
|
||||||
|
// Create a table to layout the content
|
||||||
|
HorizontalPanel dialogContents = new HorizontalPanel();
|
||||||
|
dialogContents.setSpacing(4);
|
||||||
|
dialogBox.setWidget(dialogContents);
|
||||||
|
|
||||||
|
// Add an image to the dialog
|
||||||
|
|
||||||
|
Frame image = new Frame(pgf.graphvizAbstractTree(abstractTree));
|
||||||
|
image.addStyleName("my-treeimage");
|
||||||
|
dialogContents.add(image);
|
||||||
|
|
||||||
|
// Add a close button at the bottom of the dialog
|
||||||
|
Button closeButton = new Button("Close",
|
||||||
|
new ClickListener() {
|
||||||
|
public void onClick(Widget sender) {
|
||||||
|
dialogBox.hide();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
dialogContents.add(closeButton);
|
||||||
|
|
||||||
|
dialogBox.center();
|
||||||
|
dialogBox.show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return treeBtn;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Widget createAlignButton(final String abstractTree) {
|
||||||
|
Image alignBtn = new Image("se.chalmers.cs.gf.gwt.TranslateApp/align-btn.png");
|
||||||
|
alignBtn.addClickListener(
|
||||||
|
new ClickListener() {
|
||||||
|
public void onClick(Widget sender) {
|
||||||
|
// Create a dialog box and set the caption text
|
||||||
|
final DialogBox dialogBox = new DialogBox();
|
||||||
|
dialogBox.setText("Word Alignment");
|
||||||
|
|
||||||
|
// Create a table to layout the content
|
||||||
|
HorizontalPanel dialogContents = new HorizontalPanel();
|
||||||
|
dialogContents.setSpacing(4);
|
||||||
|
dialogBox.setWidget(dialogContents);
|
||||||
|
|
||||||
|
// Add an image to the dialog
|
||||||
|
Frame image = new Frame(pgf.graphvizAlignment(abstractTree));
|
||||||
|
image.addStyleName("my-alignmentimage");
|
||||||
|
dialogContents.add(image);
|
||||||
|
|
||||||
|
// Add a close button at the bottom of the dialog
|
||||||
|
Button closeButton = new Button("Close",
|
||||||
|
new ClickListener() {
|
||||||
|
public void onClick(Widget sender) {
|
||||||
|
dialogBox.hide();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
dialogContents.add(closeButton);
|
||||||
|
|
||||||
|
dialogBox.center();
|
||||||
|
dialogBox.show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return alignBtn;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected Widget createTranslation(final String language, final String abstractTree, String text) {
|
||||||
Label l = new Label(text);
|
Label l = new Label(text);
|
||||||
l.addStyleName("my-translation");
|
l.addStyleName("my-translation");
|
||||||
String lang = pgf.getLanguageCode(language);
|
String lang = pgf.getLanguageCode(language);
|
||||||
if (lang != null) {
|
if (lang != null) {
|
||||||
l.getElement().setLang(lang);
|
l.getElement().setLang(lang);
|
||||||
}
|
}
|
||||||
|
l.addClickListener(new ClickListener() {
|
||||||
|
public void onClick(Widget sender) {
|
||||||
|
// Create a dialog box and set the caption text
|
||||||
|
final DialogBox dialogBox = new DialogBox();
|
||||||
|
dialogBox.setText("Parse Tree");
|
||||||
|
|
||||||
|
// Create a table to layout the content
|
||||||
|
HorizontalPanel dialogContents = new HorizontalPanel();
|
||||||
|
dialogContents.setSpacing(4);
|
||||||
|
dialogBox.setWidget(dialogContents);
|
||||||
|
|
||||||
|
// Add an image to the dialog
|
||||||
|
Frame image = new Frame(pgf.graphvizParseTree(abstractTree, language));
|
||||||
|
image.addStyleName("my-treeimage");
|
||||||
|
dialogContents.add(image);
|
||||||
|
|
||||||
|
// Add a close button at the bottom of the dialog
|
||||||
|
Button closeButton = new Button("Close",
|
||||||
|
new ClickListener() {
|
||||||
|
public void onClick(Widget sender) {
|
||||||
|
dialogBox.hide();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
dialogContents.add(closeButton);
|
||||||
|
|
||||||
|
dialogBox.center();
|
||||||
|
dialogBox.show();
|
||||||
|
}
|
||||||
|
});
|
||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,13 +23,40 @@
|
|||||||
.my-translations {
|
.my-translations {
|
||||||
margin-top: 1em;
|
margin-top: 1em;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.my-translation-frame {
|
||||||
|
width: 100%;
|
||||||
|
margin: 0.5em;
|
||||||
|
background: #D0E4F6;
|
||||||
|
}
|
||||||
|
|
||||||
|
.my-translation-bar {
|
||||||
|
padding-left: 25px;
|
||||||
|
padding-right: 25px;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
.my-translation {
|
.my-translation {
|
||||||
margin: 0.2em;
|
margin: 0.2em;
|
||||||
padding-left: 25px;
|
|
||||||
font-size: 150%;
|
font-size: 150%;
|
||||||
background-repeat: no-repeat;
|
background-repeat: no-repeat;
|
||||||
background-position: 0% 50%;
|
background-position: 0% 50%;
|
||||||
|
cursor:pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.my-translation-btns {
|
||||||
|
background: #DDDDDD;
|
||||||
|
cursor:pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.my-treeimage {
|
||||||
|
width: 650px;
|
||||||
|
height: 520px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.my-alignmentimage {
|
||||||
|
width: 450px;
|
||||||
|
height: 300px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
BIN
src/server/gwt/src/se/chalmers/cs/gf/gwt/public/align-btn.png
Normal file
BIN
src/server/gwt/src/se/chalmers/cs/gf/gwt/public/align-btn.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 138 B |
BIN
src/server/gwt/src/se/chalmers/cs/gf/gwt/public/tree-btn.png
Normal file
BIN
src/server/gwt/src/se/chalmers/cs/gf/gwt/public/tree-btn.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 149 B |
Reference in New Issue
Block a user