当前位置: 首页>>代码示例>>Java>>正文


Java ReadyStateChangeHandler类代码示例

本文整理汇总了Java中com.google.gwt.xhr.client.ReadyStateChangeHandler的典型用法代码示例。如果您正苦于以下问题:Java ReadyStateChangeHandler类的具体用法?Java ReadyStateChangeHandler怎么用?Java ReadyStateChangeHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ReadyStateChangeHandler类属于com.google.gwt.xhr.client包,在下文中一共展示了ReadyStateChangeHandler类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadText

import com.google.gwt.xhr.client.ReadyStateChangeHandler; //导入依赖的package包/类
public void loadText (String url, final AssetLoaderListener<String> listener) {
	XMLHttpRequest request = XMLHttpRequest.create();
	request.setOnReadyStateChange(new ReadyStateChangeHandler() {
		@Override
		public void onReadyStateChange (XMLHttpRequest xhr) {
			if (xhr.getReadyState() == XMLHttpRequest.DONE) {
				if (xhr.getStatus() != 200) {
					listener.onFailure();
				} else {
					listener.onSuccess(xhr.getResponseText());
				}
			}
		}
	});
	setOnProgress(request, listener);
	request.open("GET", url);
	request.setRequestHeader("Content-Type", "text/plain; charset=utf-8");
	request.send();
}
 
开发者ID:basherone,项目名称:libgdxcn,代码行数:20,代码来源:AssetDownloader.java

示例2: loadBinary

import com.google.gwt.xhr.client.ReadyStateChangeHandler; //导入依赖的package包/类
public void loadBinary (final String url, final AssetLoaderListener<Blob> listener) {
	XMLHttpRequest request = XMLHttpRequest.create();		
	request.setOnReadyStateChange(new ReadyStateChangeHandler() {
		@Override
		public void onReadyStateChange (XMLHttpRequest xhr) {
			if (xhr.getReadyState() == XMLHttpRequest.DONE) {
				if (xhr.getStatus() != 200) {
					listener.onFailure();
				} else {
					Int8Array data = TypedArrays.createInt8Array(xhr.getResponseArrayBuffer());
					listener.onSuccess(new Blob(data));
				}
			}
		}
	});
	setOnProgress(request, listener);
	request.open("GET", url);
	request.setResponseType(ResponseType.ArrayBuffer);
	request.send();
}
 
开发者ID:basherone,项目名称:libgdxcn,代码行数:21,代码来源:AssetDownloader.java

示例3: loadShader

import com.google.gwt.xhr.client.ReadyStateChangeHandler; //导入依赖的package包/类
/**
 * The GWT shader load is async
 *
 * @param file
 */
public void loadShader(String file, OnTextResourceLoaded listener) {
	XMLHttpRequest request = XMLHttpRequest.create();

	request.setOnReadyStateChange(new ReadyStateChangeHandler() {

		@Override
		public void onReadyStateChange(XMLHttpRequest xhr) {
			if (xhr.getReadyState() == XMLHttpRequest.DONE) {
				// ASYNC
				listener.onResourceLoaded(xhr.getResponseText());
			}
		}
	});

	request.open("GET", GWT.getHostPageBaseURL() + shaderPath + file);
	request.send();
}
 
开发者ID:mobialia,项目名称:jmini3d,代码行数:23,代码来源:ResourceLoader.java

示例4: downloadFile

import com.google.gwt.xhr.client.ReadyStateChangeHandler; //导入依赖的package包/类
private void downloadFile(final String url) {
	XMLHttpRequest request = XMLHttpRequest.create();
	request.open("GET", url);
	request.setResponseType(ResponseType.ArrayBuffer);
	request.setOnReadyStateChange(new ReadyStateChangeHandler() {
		@Override
		public void onReadyStateChange(XMLHttpRequest xhr) {
			if (xhr.getReadyState() == XMLHttpRequest.DONE) {
				downloadsInProgress--;
				if (xhr.getStatus() == 200) {
					FileItem entry = getCachedFile(url);
					entry.data = TypedArrays.createUint8Array(xhr.getResponseArrayBuffer());
					entry.dataSize = entry.data.byteLength();
					filesMemoryUsage += entry.dataSize;
					checkFilesMemory();
					context.startProcessing();
					fireReady(url);
					continueDownload();
				} else {
					GWT.log("Error downloading " + url);
					GWT.log("response status: " + xhr.getStatus() + " " + xhr.getStatusText());
					context.setStatus(ProcessingContext.STATUS_ERROR);
					fileCache.get(url).downloadStarted = false;
				}
			}
		}
	});
	request.send();
	fileCache.get(url).downloadStarted = true;
	downloadsInProgress++;
}
 
开发者ID:mateusz-matela,项目名称:djvu-html5,代码行数:32,代码来源:PageDecoder.java

示例5: addTGACanvas

import com.google.gwt.xhr.client.ReadyStateChangeHandler; //导入依赖的package包/类
private void addTGACanvas(String url) {
	XMLHttpRequest request = XMLHttpRequest.create();
	request.open("GET", url);
	request.setResponseType(ResponseType.ArrayBuffer);
	request.setOnReadyStateChange(new ReadyStateChangeHandler() {
		@Override
		public void onReadyStateChange(XMLHttpRequest xhr) {
			if(xhr.getReadyState() == XMLHttpRequest.DONE) {
				if(xhr.getStatus() >= 400) {
					// error
					System.out.println("Error");
				}
				else {
					try {
						ArrayBuffer arrayBuffer = xhr.getResponseArrayBuffer();
						Uint8ArrayNative u8array = Uint8ArrayNative.create(arrayBuffer);
						byte [] buffer = new byte[u8array.length()];
						for(int i=0; i<buffer.length; i++) {
							buffer[i] = (byte)u8array.get(i);
						}
						int pixels [] = TGAReader.read(buffer, TGAReader.ABGR);
						int width = TGAReader.getWidth(buffer);
						int height = TGAReader.getHeight(buffer);
						
						Canvas canvas = createImageCanvas(pixels, width, height);
						panel.add(canvas);
					}
					catch(Exception e) {
						e.printStackTrace();
					}
				}
			}
		}
	});
	request.send();
}
 
开发者ID:npedotnet,项目名称:TGAReader,代码行数:37,代码来源:ImageCanvasTest.java

示例6: sendRequest

import com.google.gwt.xhr.client.ReadyStateChangeHandler; //导入依赖的package包/类
public void sendRequest(MapTile tile, final UrlTileDataSource dataSource) {

		String url = mTileSource.getTileUrl(tile);

		mHttpRequest = XMLHttpRequest.create();
		mHttpRequest.open("GET", url);
		mHttpRequest.setResponseType(ResponseType.ArrayBuffer);

		mResponseHandler = new ReadyStateChangeHandler() {

			@Override
			public void onReadyStateChange(XMLHttpRequest xhr) {
				int state = xhr.getReadyState();
				//log.debug(mCurrentUrl + "response " + status + "/" + state);

				if (state == XMLHttpRequest.DONE) {
					if (xhr.getStatus() == 200) {
						Uint8Array buf = Uint8ArrayNative.create(xhr.getResponseArrayBuffer());
						dataSource.process(new Buffer(buf));
					} else {
						dataSource.process(null);
					}
					mHttpRequest = null;
				}
			}
		};

		mHttpRequest.setOnReadyStateChange(mResponseHandler);
		mHttpRequest.send();
	}
 
开发者ID:opensciencemap,项目名称:vtm,代码行数:31,代码来源:LwHttp.java

示例7: connect

import com.google.gwt.xhr.client.ReadyStateChangeHandler; //导入依赖的package包/类
@Override
public void connect(int connectionCount) {
	super.connect(connectionCount);
	read = 0;
	
	xmlHttpRequest = XMLHttpRequest.create();
	try {
		xmlHttpRequest.open("GET", getUrl(connectionCount));
		xmlHttpRequest.setRequestHeader("Accept", "application/comet");
		xmlHttpRequest.setOnReadyStateChange(new ReadyStateChangeHandler() {
			@Override
			public void onReadyStateChange(XMLHttpRequest request) {
				if (!disconnecting) {
					switch (request.getReadyState()) {
					case XMLHttpRequest.LOADING:
						onReceiving(request.getStatus(), request.getResponseText());
						break;
					case XMLHttpRequest.DONE:
						onLoaded(request.getStatus(), request.getResponseText());
						break;
					}
				}
			}
		});
		xmlHttpRequest.send();
	}
	catch (JavaScriptException e) {
		xmlHttpRequest = null;
		listener.onError(new RequestException(e.getMessage()), false);
	}
}
 
开发者ID:rzschech,项目名称:gwt-comet,代码行数:32,代码来源:HTTPRequestCometTransport.java

示例8: submitForm

import com.google.gwt.xhr.client.ReadyStateChangeHandler; //导入依赖的package包/类
public Cancellable submitForm(String aAction, RequestBuilder.Method aMethod, String aContentType, Map<String, String> aFormData, final Callback<XMLHttpRequest, XMLHttpRequest> aCallback) {
	final XMLHttpRequest req = XMLHttpRequest.create().cast();
	String urlPath = aAction != null ? aAction : "";
	List<String> parameters = new ArrayList<String>();
	for (String paramName : aFormData.keySet()) {
		parameters.add(param(paramName, aFormData.get(paramName)));
	}
               String paramsData = params(parameters.toArray(new String[] {}));
               if(aMethod != RequestBuilder.POST){
                   urlPath += "?" + paramsData;
               }
	req.open(aMethod.toString(), urlPath);
               req.setRequestHeader("Content-Type", aContentType);
	req.setOnReadyStateChange(new ReadyStateChangeHandler() {
                       @Override
		public void onReadyStateChange(final XMLHttpRequest xhr) {
			if (xhr.getReadyState() == XMLHttpRequest.DONE) {
				xhr.clearOnReadyStateChange();
				if (aCallback != null) {
                                               try {
                                                       if (xhr.getStatus() == Response.SC_OK) {
                                                               aCallback.onSuccess(xhr);
                                                       } else {
                                                               aCallback.onFailure(xhr);
                                                       }
                                               } catch (Exception ex) {
                                                       Logger.getLogger(Utils.class.getName()).log(Level.SEVERE, null, ex);
                                               }
				}
			}
		}
	});
               if(aMethod == RequestBuilder.POST){
                   req.send(paramsData);
               } else{
                   req.send();
               }
	return new Cancellable() {
		@Override
		public void cancel() {
			req.abort();
		}
	};
}
 
开发者ID:marat-gainullin,项目名称:platypus-js,代码行数:45,代码来源:AppClient.java

示例9: loadTexture

import com.google.gwt.xhr.client.ReadyStateChangeHandler; //导入依赖的package包/类
void loadTexture(String url, int index) {
	final int i = index;
    XMLHttpRequest request = XMLHttpRequest.create();
    request.open("GET", url);
    request.setResponseType(ResponseType.ArrayBuffer);
    request.setOnReadyStateChange(new ReadyStateChangeHandler() {
        @Override
        public void onReadyStateChange(XMLHttpRequest xhr) {
            if(xhr.getReadyState() == XMLHttpRequest.DONE) {
                if(xhr.getStatus() >= 400) {
                    // error
                    System.out.println("Error");
                }
                else {
                	try {
	                	ArrayBuffer arrayBuffer = xhr.getResponseArrayBuffer();
	    				Uint8ArrayNative u8array = Uint8ArrayNative.create(arrayBuffer);
	    				byte [] buffer = new byte[u8array.length()];
	    				for(int i=0; i<buffer.length; i++) {
	    					buffer[i] = (byte)u8array.get(i);
	    				}
	    				
	    				int [] pixels = TGAReader.read(buffer, TGAReader.ABGR);
	    				int width = TGAReader.getWidth(buffer);
	    				int height = TGAReader.getHeight(buffer);
	    				
	    				Canvas canvas = createImageCanvas(pixels, width, height);
	    				
	    				WebGLTexture texture = gl.createTexture();
	    				gl.enable(TEXTURE_2D);
	    				gl.bindTexture(TEXTURE_2D, texture);
	    				
	    				gl.texImage2D(TEXTURE_2D, 0, RGBA, RGBA, UNSIGNED_BYTE, canvas.getElement());

	    				gl.texParameteri(TEXTURE_2D, TEXTURE_WRAP_S, CLAMP_TO_EDGE);
	    				gl.texParameteri(TEXTURE_2D, TEXTURE_WRAP_T, CLAMP_TO_EDGE);
	    				gl.texParameteri(TEXTURE_2D, TEXTURE_MAG_FILTER, LINEAR);
	    				gl.texParameteri(TEXTURE_2D, TEXTURE_MIN_FILTER, LINEAR);
	    				
	    				textures[i] = texture;
	    				draw();
                	}
                	catch(Exception e) {
                		e.printStackTrace();
                	}
                }
            }
        }
    });
    request.send();
}
 
开发者ID:npedotnet,项目名称:TGAReader,代码行数:52,代码来源:TexturedCube.java

示例10: sendHttpRequest

import com.google.gwt.xhr.client.ReadyStateChangeHandler; //导入依赖的package包/类
@Override
public void sendHttpRequest (final HttpRequest httpRequest, final HttpResponseListener httpResultListener) {
	if (httpRequest.getUrl() == null) {
		httpResultListener.failed(new GdxRuntimeException("can't process a HTTP request without URL set"));
		return;
	}

	final String method = httpRequest.getMethod();		
	final String value = httpRequest.getContent();
	final boolean valueInBody = method.equalsIgnoreCase(HttpMethods.POST) || method.equals(HttpMethods.PUT);

       String url = httpRequest.getUrl();
       if (method.equalsIgnoreCase(HttpMethods.GET)) {
           if (value != null) {
               url += "?" + value;
           }
       } else if (method.equalsIgnoreCase(HttpMethods.POST)) {
       } else if (method.equalsIgnoreCase(HttpMethods.DELETE)) {
           if (value != null) {
               url += "?" + value;
           }
       } else if (method.equalsIgnoreCase(HttpMethods.PUT)) {
       } else {
           throw new GdxRuntimeException("Unsupported HTTP Method");
       }

       XMLHttpRequest request = XMLHttpRequest.create();

       request.setOnReadyStateChange(new ReadyStateChangeHandler() {
           @Override
           public void onReadyStateChange(XMLHttpRequest xhr) {
               if (xhr.getReadyState() == XMLHttpRequest.DONE) {
                   if (xhr.getStatus() != 200) {
                       httpResultListener.failed(new Throwable(xhr.getStatusText()));
                       requests.remove(httpRequest);
                       listeners.remove(httpRequest);
                   } else {
                       Int8Array data = TypedArrays.createInt8Array(xhr.getResponseArrayBuffer());
                       httpResultListener.handleHttpResponse(new HttpClientResponse(xhr.getStatus(), data, xhr));
                       requests.remove(httpRequest);
                       listeners.remove(httpRequest);
                   }
               }
           }
       });
       request.open(method, url);

       Map<String, String> content = httpRequest.getHeaders();
       Set<String> keySet = content.keySet();
       for (String name : keySet) {
           request.setRequestHeader(name, content.get(name));
       }
       request.setResponseType(XMLHttpRequest.ResponseType.ArrayBuffer);

       if (valueInBody)
           request.send(value);
       else
           request.send();


       requests.put(httpRequest, request);
       listeners.put(httpRequest, httpResultListener);
}
 
开发者ID:neuroradiology,项目名称:TinyVoxel,代码行数:64,代码来源:GwtNet.java

示例11: loadResourceAsync

import com.google.gwt.xhr.client.ReadyStateChangeHandler; //导入依赖的package包/类
public void loadResourceAsync(final String path, final ResourceLoader.Callback callback) {
  XMLHttpRequest req = XMLHttpRequest.create();
  
  final Exception e = new Exception();
  final int mySequenceNumber = freeSequenceNumber++;
  
  req.setOnReadyStateChange(new ReadyStateChangeHandler() {
    boolean receivingMsg;
    public void onReadyStateChange(final XMLHttpRequest xhr) {
  	if (xhr.getReadyState() == 3 && !receivingMsg) {
  	  Com.Printf("Receiving #" + mySequenceNumber + ": " + path + "\n");
  	  receivingMsg = true;
  	} else if (xhr.getReadyState() == 4) {
  	  if (mySequenceNumber < ignoreSequenceNumbersBelow) {
          Com.Printf("Ignoring outdated response #" + mySequenceNumber + ": " + path + "\n");
  	  } else {
  	    String response;
  	    if (xhr.getStatus() != 200) {
            Com.Printf("Failed to load file #" + mySequenceNumber + ": " + path + " status: " + 
          		  xhr.getStatus() + "/" + xhr.getStatusText() + "\n");
            ResourceLoader.fail(new IOException("status = " + xhr.getStatus()));
            response = null;
          } else {
            response = xhr.getResponseText();
            Com.Printf("Received response #" + mySequenceNumber + ": " + path + "\r");
          }
          readyList.add(0, new ResponseHandler(mySequenceNumber, callback, response));
          if (mySequenceNumber == currentSequenceNumber) {
            processReadyList();
          }
  	  }
      }
    }
  });

  Com.Printf("Requesting: " + path + "\n");

  overrideMimeType(req, "text/plain; charset=x-user-defined");
  req.open("GET", "/baseq2/" + path);
  req.send();
}
 
开发者ID:artemis-esf,项目名称:quake2-gwt-port,代码行数:42,代码来源:GwtResourceLoaderImpl.java


注:本文中的com.google.gwt.xhr.client.ReadyStateChangeHandler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。