下面列出了怎么用com.google.gwt.core.client.JsArrayInteger的API类实例代码及写法,或者点击链接到github查看源代码。
private native JsArrayInteger getAbsolutePosition(Element elem) /*-{
var curr = elem;
var left = 0;
var top = 0;
if ($doc.getElementById) {
do {
left += elem.offsetLeft - elem.scrollLeft;
top += elem.offsetTop - elem.scrollTop;
elem = elem.offsetParent;
curr = curr.parentNode;
while (curr != elem) {
left -= curr.scrollLeft;
top -= curr.scrollTop;
curr = curr.parentNode;
}
} while (elem.offsetParent);
}
return [left, top];
}-*/;
@Override
public JsMessage convert(Message value) {
JsMessenger messenger = JsMessenger.getInstance();
String rid = value.getRid() + "";
String sortKey = value.getSortDate() + "";
JsPeerInfo sender = messenger.buildPeerInfo(Peer.user(value.getSenderId()));
boolean isOut = value.getSenderId() == messenger.myUid();
boolean isOnServer = value.isOnServer();
String date = messenger.getFormatter().formatTime(value.getDate());
JsDate fullDate = JsDate.create(value.getDate());
JsContent content = JsContent.createContent(value.getContent(),
value.getSenderId());
JsArray<JsReaction> reactions = JsArray.createArray().cast();
for (Reaction r : value.getReactions()) {
JsArrayInteger uids = (JsArrayInteger) JsArrayInteger.createArray();
boolean isOwnSet = false;
for (Integer i : r.getUids()) {
uids.push(i);
if (i == messenger.myUid()) {
isOwnSet = true;
}
}
reactions.push(JsReaction.create(r.getCode(), uids, isOwnSet));
}
double sortDate = value.getDate() / 1000.0;
return create(rid, sortKey, sender, isOut, date, fullDate, Enums.convert(value.getMessageState()), isOnServer, content,
reactions, sortDate);
}
public static JSObject getStyle(VectorStyleDef def) {
String fillColor = def.getFill().getNormalColor();
Double fillOpacity = def.getFill().getOpacity();
String strokeColor = def.getLine().getNormalColor();
Double strokeWidth = new Double(def.getLine().getThickness());
JSObject styleObject = JSObject.createJSObject();
styleObject.setProperty(FILL_NAME, true);
styleObject.setProperty(FILL_COLOR_NAME, fillColor);
styleObject.setProperty(FILL_OPACITY_NAME, fillOpacity);
styleObject.setProperty(STROKE_COLOR_NAME, strokeColor);
styleObject.setProperty(STROKE_WIDTH_NAME, strokeWidth);
styleObject.setProperty(RADIUS_NAME, RADIUS_VALUE);
//icon
String iconUrl = def.getPoint().getExternalGraphic();
if (iconUrl != null) {
JSObject iconObject = JSObject.createJSObject();
iconObject.setProperty(ICON_URL_NAME, iconUrl);
JsArrayInteger iconSize = JSObject.createArray().cast();
iconSize.push(def.getPoint().getGraphicWidth());
iconSize.push(def.getPoint().getGraphicHeight());
JSObject iconSizeObject = iconSize.cast();
iconObject.setProperty(ICON_SIZE_NAME, iconSizeObject);
styleObject.setProperty(ICON_NAME, iconObject);
}
return styleObject;
}
public FastArrayShort() {
if(GWT.isScript()) {
stackNative = JsArrayInteger.createArray().cast();
} else {
stackJava = new JsList<Short>();
}
}
public FastArrayInteger(){
if(GWT.isScript()) {
stackNative = JsArrayInteger.createArray().cast();
} else {
stackJava = new JsList<Integer>();
}
}
/**
* Array of keycodes which will add a tag when typing in the input.
* (default: [13, 188], which are ENTER and comma)
*
* @param confirmKeys Array of keycodes
*/
public void setConfirmKeys(final List<Integer> confirmKeys) {
JsArrayInteger keys = JsArrayInteger.createArray().cast();
for(int key : confirmKeys) {
keys.push(key);
}
options.setConfirmKeys(keys);
}
public void writeFloat(float v) throws IOException {
growToFit(4);
JsArrayInteger bytes = IEEE754.fromFloat(v);
for (int i = 0; i < 4; i++) {
this.bytes[pos++] = (byte)bytes.get(i);
}
}
public void writeDouble(double v) throws IOException {
growToFit(8);
JsArrayInteger bytes = IEEE754.fromDoubleClosure(v);
for (int i = 0; i < 8; i++) {
this.bytes[pos++] = (byte)bytes.get(i);
}
}
public static native JsArrayInteger fromDoubleClosure(double a) /*-{
var f = 11; // ebits
var c = 52; // fbits
var b=(1<<f-1)-1,d,e;
if(isNaN(a))
e=(1<<b)-1,b=1,d=0;
else if(Infinity===a||-Infinity===a)
e=(1<<b)-1,b=0,d=0>a?1:0;
else if(0===a)
b=e=0,d=-Infinity===1/a?1:0;
else if(d=0>a,a=Math.abs(a),a>=Math.pow(2,1-b)){
var g=Math.min(Math.floor(Math.log(a)/Math.LN2),b);
e=g+b;
b=a*Math.pow(2,c-g)-Math.pow(2,c)
}
else
e=0,b=a/Math.pow(2,1-b-c);
for(a=[];c;c-=1)
a.push(b%2?1:0),b=Math.floor(b/2);
for(c=f;c;c-=1)
a.push(e%2?1:0),e=Math.floor(e/2);
a.push(d?1:0);
a.reverse();
f=a.join("");
for(d=[];f.length;)
d.push(parseInt(f.substring(0,8),2)),f=f.substring(8);
return d;
}-*/;
public int[] getCursorCoords() {
JsArrayInteger cc = editor.getCursorCoords();
return new int[] {cc.get(0), cc.get(1)};
}
public final native JsArrayInteger getCursorCoords() /*-{
var p = this.getCursorPositionScreen();
var c = this.renderer.textToScreenCoordinates(p.row,p.column);
return [c.pageX,c.pageY];
}-*/;
public final native JsArrayInteger getCoordsOfRowCol(int row, int column) /*-{
var p = this.getSession().documentToScreenPosition({row:row, column:column});
var c = this.renderer.textToScreenCoordinates(p.row, p.column);
return [c.pageX,c.pageY];
}-*/;
public final native JsArrayInteger getCoordsOf(GwtAcePosition pos) /*-{
var p = this.getSession().documentToScreenPosition(pos);
var c = this.renderer.textToScreenCoordinates(p.row, p.column);
return [c.pageX,c.pageY];
}-*/;
public static native JsReaction create(String reaction, JsArrayInteger uids, boolean isOwnSet)/*-{
return {reaction: reaction, uids: uids, isOwnSet: isOwnSet};
}-*/;
public VectorFeatureStyleDef getStyleDef(JSObject styleObject) {
VectorFeatureStyleDef def = new VectorFeatureStyleDef();
if (styleObject.hasProperty(LeafletStyle.FILL_COLOR_NAME)) {
String fillColor = styleObject.getPropertyAsString(LeafletStyle.FILL_COLOR_NAME);
def.getFill().setNormalColor(fillColor);
}
if (styleObject.hasProperty(LeafletStyle.FILL_OPACITY_NAME)) {
Double fillOpacity = styleObject.getPropertyAsDouble(LeafletStyle.FILL_OPACITY_NAME);
def.getFill().setOpacity(fillOpacity);
}
if (styleObject.hasProperty(LeafletStyle.STROKE_COLOR_NAME)) {
String strokeColor = styleObject.getPropertyAsString(LeafletStyle.STROKE_COLOR_NAME);
def.getLine().setNormalColor(strokeColor);
}
if (styleObject.hasProperty(LeafletStyle.STROKE_WIDTH_NAME)) {
Double strokeWidth = styleObject.getPropertyAsDouble(LeafletStyle.STROKE_WIDTH_NAME);
def.getLine().setThickness(strokeWidth.intValue());
}
JSObject iconObject = styleObject.getProperty(LeafletStyle.ICON_NAME);
if (iconObject != null) {
if (iconObject.hasProperty(LeafletStyle.ICON_URL_NAME)) {
String iconUrl = iconObject.getPropertyAsString(LeafletStyle.ICON_URL_NAME);
def.getPoint().setExternalGraphic(iconUrl);
}
if (iconObject.hasProperty(LeafletStyle.ICON_SIZE_NAME)) {
JsArrayInteger iconSize = iconObject.getProperty(LeafletStyle.ICON_SIZE_NAME).cast();
int iconWidth = iconSize.get(0);
int iconHeight = iconSize.get(1);
def.getPoint().setGraphicWidth(iconWidth);
def.getPoint().setGraphicHeight(iconHeight);
}
}
return def;
}
private static native short[] reinterpretCast( JsArrayInteger value ) /*-{
return value;
}-*/;
private static native int[] reinterpretCast( JsArrayInteger value ) /*-{
return value;
}-*/;
public native void setHiddenDays(JsArrayInteger hiddenDays) /*-{
var theInstance = this;
[email protected]eralDisplay::general.hiddenDays = hiddenDays;
}-*/;
public final native void setConfirmKeys(JsArrayInteger keys) /*-{
this.confirmKeys = keys;
}-*/;
public static native JsArrayInteger fromFloat(float v)/*-{
var ebits = 8;
var fbits = 23;
var bias = (1 << (ebits - 1)) - 1;
// Compute sign, exponent, fraction
var s, e, f;
if (isNaN(v)) {
e = (1 << bias) - 1; f = 1; s = 0;
}
else if (v === Infinity || v === -Infinity) {
e = (1 << bias) - 1; f = 0; s = (v < 0) ? 1 : 0;
}
else if (v === 0) {
e = 0; f = 0; s = (1 / v === -Infinity) ? 1 : 0;
}
else {
s = v < 0;
v = Math.abs(v);
if (v >= Math.pow(2, 1 - bias)) {
var ln = Math.min(Math.floor(Math.log(v) / Math.LN2), bias);
e = ln + bias;
f = v * Math.pow(2, fbits - ln) - Math.pow(2, fbits);
}
else {
e = 0;
f = v / Math.pow(2, 1 - bias - fbits);
}
}
// Pack sign, exponent, fraction
var i, bits = [];
for (i = fbits; i; i -= 1) { bits.push(f % 2 ? 1 : 0); f = Math.floor(f / 2); }
for (i = ebits; i; i -= 1) { bits.push(e % 2 ? 1 : 0); e = Math.floor(e / 2); }
bits.push(s ? 1 : 0);
bits.reverse();
var str = bits.join('');
// Bits to bytes
var bytes = [];
while (str.length) {
bytes.push(parseInt(str.substring(0, 8), 2));
str = str.substring(8);
}
return bytes;
}-*/;
public static native JsArrayInteger fromDouble(double v)/*-{
var ebits = 11;
var fbits = 52;
var bias = (1 << (ebits - 1)) - 1;
// Compute sign, exponent, fraction
var s, e, f;
if (isNaN(v)) {
e = (1 << bias) - 1; f = 1; s = 0;
}
else if (v === Infinity || v === -Infinity) {
e = (1 << bias) - 1; f = 0; s = (v < 0) ? 1 : 0;
}
else if (v === 0) {
e = 0; f = 0; s = (1 / v === -Infinity) ? 1 : 0;
}
else {
s = v < 0;
v = Math.abs(v);
if (v >= Math.pow(2, 1 - bias)) {
var ln = Math.min(Math.floor(Math.log(v) / Math.LN2), bias);
e = ln + bias;
f = v * Math.pow(2, fbits - ln) - Math.pow(2, fbits);
}
else {
e = 0;
f = v / Math.pow(2, 1 - bias - fbits);
}
}
// Pack sign, exponent, fraction
var i, bits = [];
for (i = fbits; i; i -= 1) { bits.push(f % 2 ? 1 : 0); f = Math.floor(f / 2); }
for (i = ebits; i; i -= 1) { bits.push(e % 2 ? 1 : 0); e = Math.floor(e / 2); }
bits.push(s ? 1 : 0);
bits.reverse();
var str = bits.join('');
// Bits to bytes
var bytes = [];
while (str.length) {
bytes.push(parseInt(str.substring(0, 8), 2));
str = str.substring(8);
}
return bytes;
}-*/;
/**
* Sorts a JsArray of integers.
*
* @param sortMe Array to be sorted.
* @param comparator Comparator to be used, per native JS sort() method.
*/
public static native void sort(JsArrayInteger sortMe, JavaScriptObject comparator) /*-{
sortMe.sort(comparator);
}-*/;
/**
* Sorts a JsArray of integers.
*
* @param sortMe Array to be sorted.
* @param comparator Comparator to be used, per native JS sort() method.
*/
public static native void sort(JsArrayInteger sortMe, JavaScriptObject comparator) /*-{
sortMe.sort(comparator);
}-*/;