📄 application.java
字号:
/* * Copyright (c) 2007 Sun Microsystems, Inc. All rights reserved. * * Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product that is * described in this document. In particular, and without limitation, these intellectual property rights may * include one or more of the U.S. patents listed at http://www.sun.com/patents and one or more additional patents * or pending patent applications in the U.S. and in other countries. * * U.S. Government Rights - Commercial software. Government users are subject to the Sun Microsystems, Inc. * standard license agreement and applicable provisions of the FAR and its supplements. * * Use is subject to license terms. * * This distribution may include materials developed by third parties. Sun, Sun Microsystems, the Sun logo and * Java are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. * * Copyright (c) 2006 Sun Microsystems, Inc. Tous droits r?serv?s. * * Sun Microsystems, Inc. d?tient les droits de propri?t? intellectuels relatifs ? la technologie incorpor?e dans * le produit qui est d?crit dans ce document. En particulier, et ce sans limitation, ces droits de propri?t? * intellectuelle peuvent inclure un ou plus des brevets am?ricains list?s ? l'adresse http://www.sun.com/patents * et un ou les brevets suppl?mentaires ou les applications de brevet en attente aux Etats - Unis et dans les * autres pays. * * L'utilisation est soumise aux termes du contrat de licence. * * Cette distribution peut comprendre des composants d?velopp?s par des tierces parties. * Sun, Sun Microsystems, le logo Sun et Java sont des marques de fabrique ou des marques d?pos?es de Sun * Microsystems, Inc. aux Etats-Unis et dans d'autres pays. */package com.sun.spot.spotworld.participants; import com.sun.spot.spotworld.common.LocaleUtil;import com.sun.spot.spotworld.common.UICommand;import com.sun.spot.spotworld.gui.IUIApplication;import com.sun.spot.spotworld.gui.IUIObject;//import com.sun.spot.spotworld.gui.RemotePrintHandler;import com.sun.spot.spotworld.virtualobjects.VirtualObject;import java.util.Vector;import org.sunspotworld.remoteprinting.RemotePrintHandler;/** * A proxy to an application running on some SPOT out there somewhere. * @author randy */public class Application extends VirtualObject { private static Vector<RemotePrintHandler> remotePrintHandlers = new Vector<RemotePrintHandler>(); public static enum AppState {RUNNING, PAUSED, EXITED, NEW, BEING_DEBUGGED, MIGRATING}; private AppState state = AppState.RUNNING; public static boolean ALLOW_APP_MIGRATION = false; public Application() { } private SquawkHost host; private String isolateID; //The long, universally unique id for this isolate. All the other name bits are derived from this. //TO DO Remove these 4 fields, they are mearly chaches and requests for their values should be replaced by computed answers private String className; private String sourceAddress; private String packageName; private int idCount; public Vector<UICommand> getApplicationMethods() { Vector<UICommand> methods = new Vector<UICommand>(); methods.addElement(new UICommand() { public String getName() { return LocaleUtil.getString("pause"); } public String getToolTip() { return "Pause this Application"; } public void run(IUIObject obj) { pause(); } }); methods.addElement(new UICommand() { public String getName() { return LocaleUtil.getString("resume"); } public String getToolTip() { return "Resume this Application"; } public void run(IUIObject obj) { resume(); } }); methods.addElement(new UICommand() { public String getName() { return LocaleUtil.getString("exit"); } public String getToolTip() { return "Exit this Application"; } public void run(IUIObject obj) { exit(); } }); methods.addElement(new UICommand() { public String getName() { return LocaleUtil.getString("Start remote printing"); } public String getToolTip() { return "open a window that captures a radio stream from System.out"; } public void run(IUIObject obj) { ((IUIApplication)obj).startRemotePrinting(); } }); methods.addElement(new UICommand() { public String getName() { return LocaleUtil.getString("refresh"); } public String getToolTip() { return "Update this representation"; } public void run(IUIObject obj) { refresh(); } }); return methods; } public void pause(){ ((SunSPOT)getHost()).sendSPOTMessage("PAUSE_APP", isolateID); } public void resume(){ ((SunSPOT)getHost()).sendSPOTMessage("RESUME_APP", isolateID); } public void stopRemotePrinting(int portNumber){ ((SunSPOT)getHost()).sendSPOTMessage("STOP_REMOTE_PRINT_APP", isolateID, "" + portNumber ); } public void exit(){ ((SunSPOT)getHost()).sendSPOTMessage("EXIT_APP", isolateID); } public void refresh(){ Vector[] reply = ((SunSPOT)getHost()).sendSPOTMessage("GET_APP_STATUS", isolateID); ((SunSPOT) getHost()).appStatus((String) reply[0].elementAt(0), (String) reply[0].elementAt(1) ); } public SquawkHost getHost() { return (SquawkHost) host; } public String getUniqueID(){ return getIsolateID(); } public void setIsolateID(String isoID){ isolateID = isoID; String[] strs0 = isoID.split("@"); sourceAddress = strs0[1]; String[] strs1 = strs0[0].split("#"); String fullClassName = strs1[0]; idCount = (new Integer(strs1[1])).intValue(); String[] strs2 = fullClassName.split("\\."); className = strs2[strs2.length - 1]; packageName = ""; for (int i = 0; i < strs2.length - 1; i++) { packageName = packageName + strs2[i]; if(i < strs2.length - 2) packageName = packageName + "."; } } public String toString(){ return super.toString() + ": " + getName(); } /* * This can be called when the object has no UI. Or, it may have * a UI AND an existing host. */ public void setHost(SquawkHost host) { msg(" Setting a host for the application to be " + host); this.host = host; // Now in the inconsistent state of being graphically associated with the wrong host! // Notify the UI so this can be repaired. notifyUIObjects(); } public String getName() { return getIsolateID(); } public AppState getState() { return state; } public void setState(AppState newState) { state = newState; notifyUIObjects(); } public String getClassName() { return className; } public void setClassName(String className) { this.className = className; } public String getSourceAddress() { return sourceAddress; } public void setSourceAddress(String sourceAddress) { this.sourceAddress = sourceAddress; } public String getPackageName() { return packageName; } public void setPackageName(String packageName) { this.packageName = packageName; } public int getIdCount() { return idCount; } public void setIdCount(int idCount) { this.idCount = idCount; } public String getIsolateID() { return isolateID; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -