use of com.google.gwt.core.client.JsArrayString in project actor-platform by actorapp.
the class JsContent method createContent.
public static JsContent createContent(AbsContent src, int sender) {
JsMessenger messenger = JsMessenger.getInstance();
JsContent content;
if (src instanceof TextContent) {
TextContent textContent = (TextContent) src;
if (textContent.getTextMessageEx() instanceof ApiTextModernMessage) {
ApiTextModernMessage modernMessage = (ApiTextModernMessage) textContent.getTextMessageEx();
String text = modernMessage.getText();
JsParagraphStyle paragraphStyle = JsParagraphStyle.create(modernMessage.getStyle());
JsArray<JsAttach> attaches = JsArray.createArray().cast();
for (ApiTextModernAttach srcAttach : modernMessage.getAttaches()) {
JsArray<JsAttachField> fields = JsArray.createArray().cast();
for (ApiTextModernField f : srcAttach.getFields()) {
boolean isShort = f.isShort() != null ? f.isShort() : true;
fields.push(JsAttachField.create(f.getTitle(), f.getValue(), isShort));
}
attaches.push(JsAttach.create(srcAttach.getTitle(), srcAttach.getTitleUrl(), srcAttach.getText(), JsParagraphStyle.create(srcAttach.getStyle()), fields));
}
content = JsContentTextModern.create(text, paragraphStyle, attaches);
} else {
content = JsContentText.create(((TextContent) src).getText());
}
} else if (src instanceof ServiceContent) {
content = JsContentService.create(messenger.getFormatter().formatFullServiceMessage(sender, (ServiceContent) src, false));
} else if (src instanceof DocumentContent) {
DocumentContent doc = (DocumentContent) src;
String fileName = doc.getName();
String fileExtension = doc.getExt();
String fileSize = messenger.getFormatter().formatFileSize(doc.getSource().getSize());
String fileUrl = null;
if (doc.getSource() instanceof FileRemoteSource) {
fileUrl = messenger.getFileUrl(((FileRemoteSource) doc.getSource()).getFileReference());
}
boolean isUploading = doc.getSource() instanceof FileLocalSource;
String thumb = null;
if (doc.getFastThumb() != null) {
String thumbBase64 = Base64Utils.toBase64(doc.getFastThumb().getImage());
thumb = "data:image/jpg;base64," + thumbBase64;
}
if (src instanceof PhotoContent && thumb != null) {
PhotoContent photoContent = (PhotoContent) src;
content = JsContentPhoto.create(fileName, fileExtension, fileSize, photoContent.getW(), photoContent.getH(), thumb, fileUrl, isUploading);
} else if (src instanceof AnimationContent) {
AnimationContent animationContent = (AnimationContent) src;
content = JsContentAnimation.create(fileName, fileExtension, fileSize, animationContent.getW(), animationContent.getH(), thumb, fileUrl, isUploading);
} else if (src instanceof VoiceContent) {
VoiceContent voiceContent = (VoiceContent) src;
content = JsContentVoice.create(fileName, fileExtension, fileSize, fileUrl, isUploading, voiceContent.getDuration());
} else {
content = JsContentDocument.create(fileName, fileExtension, fileSize, thumb, fileUrl, isUploading);
}
} else if (src instanceof StickerContent) {
StickerContent sticker = (StickerContent) src;
ImageLocation stickerImage = sticker.getImage256();
if (sticker.getImage512() != null) {
stickerImage = sticker.getImage512();
}
String fileUrl = messenger.getFileUrl(stickerImage.getReference());
String fileSize = messenger.getFormatter().formatFileSize(stickerImage.getReference().getFileSize());
content = JsContentSticker.create(stickerImage.getReference().getFileName(), ".webp", fileSize, stickerImage.getWidth(), stickerImage.getHeight(), null, fileUrl, false);
} else if (src instanceof ContactContent) {
ContactContent contactContent = (ContactContent) src;
JsArrayString phones = JsArray.createArray().cast();
JsArrayString emails = JsArray.createArray().cast();
for (String s : contactContent.getEmails()) {
emails.push(s);
}
for (String s : contactContent.getPhones()) {
phones.push(s);
}
content = JsContentContact.create(contactContent.getName(), contactContent.getPhoto64(), phones, emails);
} else if (src instanceof LocationContent) {
LocationContent locationContent = (LocationContent) src;
content = JsContentLocation.create(locationContent.getLongitude(), locationContent.getLatitude(), locationContent.getStreet(), locationContent.getPlace());
} else {
content = JsContentUnsupported.create();
}
return content;
}
use of com.google.gwt.core.client.JsArrayString in project perun by CESNET.
the class JsonUtils method listFromJsArrayString.
/**
* Returns a Java List from JsArrayString.
*
* @param jsa javascript array of strings
* @return ArrayList<String> list of strings
*/
public static ArrayList<String> listFromJsArrayString(JsArrayString jsa) {
ArrayList<String> arrayList = new ArrayList<String>();
for (int i = 0; i < jsa.length(); i++) {
String str = jsa.get(i).toString();
arrayList.add(str);
}
return arrayList;
}
use of com.google.gwt.core.client.JsArrayString in project perun by CESNET.
the class PreferredShellsWidget method calculateAttrValue.
/**
* Takes values from input boxes and
* stores them to attribute
*/
private void calculateAttrValue() {
if (shellList.isEmpty()) {
// clear value if empty
a.setValueAsJso(null);
} else {
// fill value
JsArrayString array = JavaScriptObject.createArray().cast();
for (ListBox box : shellList) {
String newValue = box.getValue(box.getSelectedIndex());
if (newValue.equals(CUSTOM_TEXT)) {
// process textbox
if (!customMap.get(box).getTextBox().getText().trim().isEmpty()) {
// store only non-empty values
array.push(customMap.get(box).getTextBox().getText().trim());
}
} else {
array.push(newValue);
}
}
a.setValueAsJsArray(array);
}
}
use of com.google.gwt.core.client.JsArrayString in project gerrit by GerritCodeReview.
the class Unified method newCm.
@Override
CodeMirror newCm(DiffInfo.FileMeta meta, String contents, Element parent) {
JsArrayString gutters = JavaScriptObject.createArray().cast();
gutters.push(UnifiedTable.style.lineNumbersLeft());
gutters.push(UnifiedTable.style.lineNumbersRight());
return CodeMirror.create(parent, Configuration.create().set("cursorBlinkRate", prefs.cursorBlinkRate()).set("cursorHeight", 0.85).set("gutters", gutters).set("inputStyle", "textarea").set("keyMap", "vim_ro").set("lineNumbers", false).set("lineWrapping", prefs.lineWrapping()).set("matchBrackets", prefs.matchBrackets()).set("mode", getFileSize() == FileSize.SMALL ? getContentType(meta) : null).set("readOnly", true).set("scrollbarStyle", "overlay").set("styleSelectedText", true).set("showTrailingSpace", prefs.showWhitespaceErrors()).set("tabSize", prefs.tabSize()).set("theme", prefs.theme().name().toLowerCase()).set("value", meta != null ? contents : "").set("viewportMargin", renderEntireFile() ? POSITIVE_INFINITY : 10));
}
use of com.google.gwt.core.client.JsArrayString in project gerrit by GerritCodeReview.
the class UnifiedChunkManager method render.
private int render(Region region, int cmLine, boolean useIntralineBg) {
int startA = lineMapper.getLineA();
int startB = lineMapper.getLineB();
JsArrayString a = region.a();
JsArrayString b = region.b();
int aLen = a != null ? a.length() : 0;
int bLen = b != null ? b.length() : 0;
boolean insertOrDelete = a == null || b == null;
colorLines(cm, insertOrDelete && !useIntralineBg ? UnifiedTable.style.diffDelete() : UnifiedTable.style.intralineDelete(), cmLine, aLen);
colorLines(cm, insertOrDelete && !useIntralineBg ? UnifiedTable.style.diffInsert() : UnifiedTable.style.intralineInsert(), cmLine + aLen, bLen);
markEdit(DisplaySide.A, cmLine, a, region.editA());
markEdit(DisplaySide.B, cmLine + aLen, b, region.editB());
// TODO: verify addGutterTag
addGutterTag(region, cmLine);
lineMapper.appendReplace(aLen, bLen);
int endA = lineMapper.getLineA() - 1;
int endB = lineMapper.getLineB() - 1;
if (aLen > 0) {
addDiffChunk(DisplaySide.A, endA, aLen, cmLine, bLen > 0);
for (int j = 0; j < aLen; j++) {
host.setLineNumber(DisplaySide.A, cmLine + j, startA + j + 1);
host.setLineNumberEmpty(DisplaySide.B, cmLine + j);
}
}
if (bLen > 0) {
addDiffChunk(DisplaySide.B, endB, bLen, cmLine + aLen, aLen > 0);
for (int j = 0; j < bLen; j++) {
host.setLineNumberEmpty(DisplaySide.A, cmLine + aLen + j);
host.setLineNumber(DisplaySide.B, cmLine + aLen + j, startB + j + 1);
}
}
return aLen + bLen;
}
Aggregations