Revision: 6301 Author: [email protected] Date: Mon Oct 5 15:54:05 2009 Log: Changes to support passing icons as byte arrays (so eventually we can get them from the running client), misc cleanups.
http://code.google.com/p/google-web-toolkit/source/detail?r=6301 Modified: /changes/jat/abstractui/dev/core/src/com/google/gwt/dev/HostedModeBase.java /changes/jat/abstractui/dev/core/src/com/google/gwt/dev/SwingUI.java /changes/jat/abstractui/dev/core/src/com/google/gwt/dev/shell/BrowserWidgetHost.java /changes/jat/abstractui/dev/oophm/overlay/com/google/gwt/dev/GWTShell.java /changes/jat/abstractui/dev/oophm/overlay/com/google/gwt/dev/HostedMode.java /changes/jat/abstractui/dev/oophm/src/com/google/gwt/dev/ModuleTabPanel.java /changes/jat/abstractui/dev/oophm/src/com/google/gwt/dev/shell/BrowserChannel.java /changes/jat/abstractui/dev/oophm/src/com/google/gwt/dev/shell/BrowserChannelServer.java /changes/jat/abstractui/dev/oophm/src/com/google/gwt/dev/shell/HtmlUnitSessionHandler.java /changes/jat/abstractui/dev/oophm/src/com/google/gwt/dev/shell/OophmSessionHandler.java /changes/jat/abstractui/dev/oophm/src/com/google/gwt/dev/util/BrowserInfo.java ======================================= --- /changes/jat/abstractui/dev/core/src/com/google/gwt/dev/HostedModeBase.java Fri Oct 2 16:13:44 2009 +++ /changes/jat/abstractui/dev/core/src/com/google/gwt/dev/HostedModeBase.java Mon Oct 5 15:54:05 2009 @@ -122,7 +122,18 @@ private final Map<String, Callback> callbacks = new HashMap<String, Callback>(); - public abstract TreeLogger getTopLogger(TreeLogger.Type logLevel); + /** + * Create a top-level logger for messages which are not associated with the + * web server or any module. Defaults to logging to stdout. + * + * @param logLevel + * @return TreeLogger instance to use + */ + public TreeLogger getTopLogger(TreeLogger.Type logLevel) { + PrintWriterTreeLogger logger = new PrintWriterTreeLogger(); + logger.setMaxDetail(logLevel); + return logger; + } /** * Create the web server portion of the UI if not already created, and @@ -130,11 +141,12 @@ * * @param serverName short name of the web server or null if only the icon * should be used - * @param iconName name of the icon as a classpath resource + * @param serverIcon byte array containing an icon (fitting into 24x24) to + * use for the server, or null if only the name should be used * @return TreeLogger instance */ public abstract TreeLogger getWebServerLogger(String serverName, - String iconName); + byte[] serverIcon); /** * Initialize the UI. @@ -153,12 +165,14 @@ * @param sessionKey a unique session key * @param agentTag short-form user agent identifier, suitable for use in * a label for this connection + * @param agentIcon icon to use for the user agent (fits inside 24x24) or + * null if unavailable * @param logLevel logging detail requested * @return a handle to the module */ public abstract ModuleHandle loadModule(String userAgent, String remoteSocket, String url, String tabKey, String moduleName, - String sessionKey, String agentTag, Type logLevel); + String sessionKey, String agentTag, byte[] agentIcon, Type logLevel); /** * Set a callback for the UI to report events. @@ -206,7 +220,7 @@ public ModuleSpaceHost createModuleSpaceHost(TreeLogger mainLogger, String moduleName, String userAgent, String url, String tabKey, - String sessionKey, String remoteSocket) + String sessionKey, String remoteSocket, byte[] userAgentIcon) throws UnableToCompleteException { if (sessionKey == null) { // if we don't have a unique session key, make one up @@ -214,9 +228,9 @@ } TreeLogger logger = mainLogger; TreeLogger.Type maxLevel = options.getLogLevel(); - String agentTag = BrowserInfo.getShortName(userAgent).toLowerCase(); + String agentTag = BrowserInfo.getShortName(userAgent); ModuleHandle module = ui.loadModule(userAgent, remoteSocket, url, tabKey, - moduleName, sessionKey, agentTag, maxLevel); + moduleName, sessionKey, agentTag, userAgentIcon, maxLevel); logger = module.getLogger(); try { // Try to find an existing loaded version of the module def. ======================================= --- /changes/jat/abstractui/dev/core/src/com/google/gwt/dev/SwingUI.java Fri Oct 2 16:13:44 2009 +++ /changes/jat/abstractui/dev/core/src/com/google/gwt/dev/SwingUI.java Mon Oct 5 15:54:05 2009 @@ -142,7 +142,7 @@ } @Override - public TreeLogger getWebServerLogger(String serverName, String iconName) { + public TreeLogger getWebServerLogger(String serverName, byte[] serverIcon) { if (hostedModeBase.isHeadless()) { return topLogger; } @@ -158,8 +158,11 @@ webServerLog = new WebServerPanel(hostedModeBase.getPort(), hostedModeBase.options.getLogLevel(), hostedModeBase.options.getLogFile("webserver.log"), restartAction); - Icon serverIcon = null; - tabs.insertTab(serverName, serverIcon, webServerLog, null, 1); + Icon serverIconImage = null; + if (serverIcon != null) { + serverIconImage = new ImageIcon(serverIcon); + } + tabs.insertTab(serverName, serverIconImage, webServerLog, null, 1); } return webServerLog.getLogger(); } @@ -198,13 +201,13 @@ @Override public ModuleHandle loadModule(String userAgent, String remoteSocket, String url, String tabKey, String moduleName, String sessionKey, - String agentTag, TreeLogger.Type logLevel) { + String agentTag, byte[] agentIcon, TreeLogger.Type logLevel) { ModuleTabPanel tabPanel = null; ModulePanel tab = null; TreeLogger logger; if (!hostedModeBase.isHeadless()) { tabPanel = findModuleTab(userAgent, remoteSocket, url, tabKey, - moduleName); + moduleName, agentIcon); tab = tabPanel.addModuleSession(logLevel, moduleName, sessionKey, hostedModeBase.options.getLogFile(String.format("%s-%s-%d.log", moduleName, agentTag, @@ -257,7 +260,7 @@ } private ModuleTabPanel findModuleTab(String userAgent, String remoteSocket, - String url, String tabKey, String moduleName) { + String url, String tabKey, String moduleName, byte[] agentIcon) { int hostEnd = remoteSocket.indexOf(':'); if (hostEnd < 0) { hostEnd = remoteSocket.length(); @@ -268,7 +271,7 @@ ModuleTabPanel moduleTabPanel = tabPanels.get(key); if (moduleTabPanel == null) { moduleTabPanel = new ModuleTabPanel(userAgent, remoteSocket, url, - new TabPanelCollection() { + agentIcon, new TabPanelCollection() { public void addTab(ModuleTabPanel tabPanel, ImageIcon icon, String title, String tooltip) { synchronized (tabs) { ======================================= --- /changes/jat/abstractui/dev/core/src/com/google/gwt/dev/shell/BrowserWidgetHost.java Sun Sep 20 12:33:31 2009 +++ /changes/jat/abstractui/dev/core/src/com/google/gwt/dev/shell/BrowserWidgetHost.java Mon Oct 5 15:54:05 2009 @@ -52,13 +52,16 @@ * can't distinguish tabs or null if using an old browser plugin * @param sessionKey unique session key, may be null for old browser plugins * @param remoteEndpoint + * @param userAgentIcon byte array containing an icon (which fits in 24x24) + * for this user agent or null if unavailable * * TODO(jat): change remoteEndpoint to be a BrowserChannelServer instance * when we remove the SWT implementation */ ModuleSpaceHost createModuleSpaceHost(TreeLogger logger, String moduleName, String userAgent, String url, String tabKey, String sessionKey, - String remoteEndpoint) throws UnableToCompleteException; + String remoteEndpoint, byte[] userAgentIcon) + throws UnableToCompleteException; TreeLogger getLogger(); ======================================= --- /changes/jat/abstractui/dev/oophm/overlay/com/google/gwt/dev/GWTShell.java Fri Oct 2 08:37:20 2009 +++ /changes/jat/abstractui/dev/oophm/overlay/com/google/gwt/dev/GWTShell.java Mon Oct 5 15:54:05 2009 @@ -242,6 +242,7 @@ @Override protected int doStartUpServer() { + // TODO(jat): find a safe way to get an icon for Tomcat TreeLogger logger = ui.getWebServerLogger("Tomcat", null); // TODO(bruce): make tomcat work in terms of the modular launcher String whyFailed = EmbeddedTomcatServer.start(isHeadless() ? getTopLogger() ======================================= --- /changes/jat/abstractui/dev/oophm/overlay/com/google/gwt/dev/HostedMode.java Fri Oct 2 09:35:30 2009 +++ /changes/jat/abstractui/dev/oophm/overlay/com/google/gwt/dev/HostedMode.java Mon Oct 5 15:54:05 2009 @@ -385,6 +385,7 @@ } } }); + // TODO(jat): find a safe way to get an icon for the servlet container TreeLogger serverLogger = ui.getWebServerLogger(getWebServerName(), null); serverLogger.log(TreeLogger.INFO, "Starting HTTP on port " + getPort(), null); @@ -460,8 +461,6 @@ * * @param logger the logger to use * @param module the module to link - * @param includePublicFiles if <code>true</code>, include public files in - * the link, otherwise do not include them * @throws UnableToCompleteException */ private void link(TreeLogger logger, ModuleDef module) ======================================= --- /changes/jat/abstractui/dev/oophm/src/com/google/gwt/dev/ModuleTabPanel.java Fri Oct 2 08:37:20 2009 +++ /changes/jat/abstractui/dev/oophm/src/com/google/gwt/dev/ModuleTabPanel.java Mon Oct 5 15:54:05 2009 @@ -304,12 +304,14 @@ * @param userAgent * @param remoteSocket * @param url + * @param agentIconBytes * @param tabPanelCollection * @param moduleName used just for the tab name in the event that the plugin * is an older version that doesn't supply the url */ public ModuleTabPanel(String userAgent, String remoteSocket, String url, - TabPanelCollection tabPanelCollection, String moduleName) { + byte[] agentIconBytes, TabPanelCollection tabPanelCollection, + String moduleName) { super(new BorderLayout()); this.tabPanelCollection = tabPanelCollection; topPanel = new JPanel(); @@ -351,7 +353,6 @@ cardLayout = new CardLayout(); deckPanel.setLayout(cardLayout); add(deckPanel); - BrowserInfo browserInfo = BrowserInfo.getBrowserInfo(userAgent); // Construct the tab title and tooltip String tabTitle = url; @@ -380,8 +381,11 @@ } } - ImageIcon browserIcon = browserInfo.getIcon(); - String shortName = browserInfo.getShortName(); + ImageIcon browserIcon = null; + if (agentIconBytes != null) { + browserIcon = new ImageIcon(agentIconBytes); + } + String shortName = BrowserInfo.getShortName(userAgent); if (browserIcon == null) { if (shortName != null) { tabTitle += " (" + shortName + ")"; ======================================= --- /changes/jat/abstractui/dev/oophm/src/com/google/gwt/dev/shell/BrowserChannel.java Fri Sep 25 20:31:26 2009 +++ /changes/jat/abstractui/dev/oophm/src/com/google/gwt/dev/shell/BrowserChannel.java Mon Oct 5 15:54:05 2009 @@ -246,11 +246,13 @@ * @param tabKey opaque key of the tab, may be empty if the plugin can't * distinguish tabs or null if using an old plugin * @param sessionKey opaque key for this session, null if using an old plugin + * @param userAgentIcon byte array containing an icon (which fits within + * 24x24) representing the user agent or null if unavailable * @return a TreeLogger to use for the module's logs */ public abstract TreeLogger loadModule(TreeLogger logger, BrowserChannel channel, String moduleName, String userAgent, String url, - String tabKey, String sessionKey); + String tabKey, String sessionKey, byte[] userAgentIcon); public abstract ExceptionOrReturnValue setProperty(BrowserChannel channel, int refId, int dispId, Value newValue); ======================================= --- /changes/jat/abstractui/dev/oophm/src/com/google/gwt/dev/shell/BrowserChannelServer.java Fri Sep 25 11:00:02 2009 +++ /changes/jat/abstractui/dev/oophm/src/com/google/gwt/dev/shell/BrowserChannelServer.java Mon Oct 5 15:54:05 2009 @@ -309,6 +309,8 @@ String url = null; String tabKey = null; String sessionKey = null; + // TODO(jat): add a way to get the user agent icon + byte[] userAgentIcon = null; switch (type) { case OLD_LOAD_MODULE: // v1 client @@ -389,7 +391,7 @@ "Hosting " + moduleName + " for " + userAgent + " on " + url + " @ " + sessionKey); logger = handler.loadModule(logger, this, moduleName, userAgent, url, - tabKey, sessionKey); + tabKey, sessionKey, userAgentIcon); try { // send LoadModule response ReturnMessage.send(this, false, new Value()); ======================================= --- /changes/jat/abstractui/dev/oophm/src/com/google/gwt/dev/shell/HtmlUnitSessionHandler.java Wed Sep 30 09:31:26 2009 +++ /changes/jat/abstractui/dev/oophm/src/com/google/gwt/dev/shell/HtmlUnitSessionHandler.java Mon Oct 5 15:54:05 2009 @@ -181,12 +181,12 @@ Context jsContext = Context.getCurrentContext(); ScriptableObject jsThis; if (thisObj.getType() == ValueType.NULL) { - jsThis = (ScriptableObject) window; + jsThis = window; } else { jsThis = (ScriptableObject) makeJsvalFromValue(jsContext, thisObj); } Object functionObject = ScriptableObject.getProperty( - (ScriptableObject) window, methodName); + window, methodName); if (functionObject == ScriptableObject.NOT_FOUND) { logger.log(TreeLogger.ERROR, "function " + methodName + " NOT FOUND, thisObj: " + jsThis + ", methodName: " + methodName); @@ -248,7 +248,7 @@ @Override public TreeLogger loadModule(TreeLogger logger, BrowserChannel channel, String moduleName, String userAgent, String url, String tabKey, - String sessionKey) { + String sessionKey, byte[] userAgentIcon) { throw new UnsupportedOperationException("loadModule must not be called"); } @@ -274,7 +274,7 @@ return new Value(scriptableValue.toString()); } } - Integer refId = jsObjectToRef.get((Scriptable) value); + Integer refId = jsObjectToRef.get(value); if (refId == null) { refId = nextRefId++; jsObjectToRef.put((Scriptable) value, refId); ======================================= --- /changes/jat/abstractui/dev/oophm/src/com/google/gwt/dev/shell/OophmSessionHandler.java Fri Sep 25 11:00:02 2009 +++ /changes/jat/abstractui/dev/oophm/src/com/google/gwt/dev/shell/OophmSessionHandler.java Mon Oct 5 15:54:05 2009 @@ -156,8 +156,9 @@ @Override public TreeLogger loadModule(TreeLogger loadModuleLogger, BrowserChannel channel, String moduleName, String userAgent, String url, - String tabKey, String sessionKey) { + String tabKey, String sessionKey, byte[] userAgentIcon) { logger = loadModuleLogger; + // Add a way to get the icon from the client. try { // Attach a new ModuleSpace to make it programmable. // @@ -166,7 +167,7 @@ BrowserChannelServer serverChannel = (BrowserChannelServer) channel; ModuleSpaceHost msh = host.createModuleSpaceHost(loadModuleLogger, moduleName, userAgent, url, tabKey, sessionKey, - channel.getRemoteEndpoint()); + channel.getRemoteEndpoint(), userAgentIcon); logger = msh.getLogger(); ModuleSpace moduleSpace = new ModuleSpaceOOPHM(msh, moduleName, serverChannel); ======================================= --- /changes/jat/abstractui/dev/oophm/src/com/google/gwt/dev/util/BrowserInfo.java Thu Sep 17 15:13:42 2009 +++ /changes/jat/abstractui/dev/oophm/src/com/google/gwt/dev/util/BrowserInfo.java Mon Oct 5 15:54:05 2009 @@ -15,10 +15,6 @@ */ package com.google.gwt.dev.util; -import com.google.gwt.dev.shell.Icons; - -import javax.swing.ImageIcon; - /** * Holds information about the browser used in the UI. */ @@ -32,29 +28,12 @@ private static final String IE = "IE"; /** - * Choose an icon and short name appropriate for this browser. The icon - * may be null. + * Retrieve a short name, suitable for use in a tab or filename, for a given + * user agent. * - * @param userAgent User-Agent string from browser - * @return icon or null if none + * @param userAgent + * @return short name of user agent */ - public static BrowserInfo getBrowserInfo(String userAgent) { - ImageIcon browserIcon = null; - String shortName = getShortName(userAgent); - if (shortName.equals(IE)) { - browserIcon = Icons.getIE24(); - } else if (shortName.equals(CHROME)) { - browserIcon = Icons.getChrome24(); - } else if (shortName.equals(OPERA)) { - // no icon for Opera - } else if (shortName.equals(SAFARI)) { - browserIcon = Icons.getSafari24(); - } else if (shortName.equals(FIREFOX)) { - browserIcon = Icons.getFirefox24(); - } - return new BrowserInfo(browserIcon, shortName); - } - public static String getShortName(String userAgent) { String lcAgent = userAgent.toLowerCase(); if (lcAgent.contains("msie")) { @@ -70,31 +49,7 @@ } return UNKNOWN; } - private final ImageIcon icon; - private final String shortName; - - /** - * Create a BrowserInfo instance. - * - * @param icon - * @param shortName - */ - private BrowserInfo(ImageIcon icon, String shortName) { - this.icon = icon; - this.shortName = shortName; - } - - /** - * @return the icon used to identify this browser, or null if none. - */ - public ImageIcon getIcon() { - return icon; - } - - /** - * @return the short name used to identify this browser, or null if none. - */ - public String getShortName() { - return shortName; + + private BrowserInfo() { } } --~--~---------~--~----~------------~-------~--~----~ http://groups.google.com/group/Google-Web-Toolkit-Contributors -~----------~----~----~----~------~----~------~--~---
