001: package com.canoo.webtest.extension.applet.runner;
002:
003: import com.canoo.webtest.extension.applet.AbstractAppletTag;
004:
005: import java.applet.Applet;
006: import java.applet.AppletContext;
007: import java.applet.AppletStub;
008: import java.awt.Dimension;
009: import java.awt.Frame;
010: import java.net.URL;
011:
012: /**
013: * @author Denis N. Antonioli
014: */
015: public abstract class AbstractAppletStub implements AppletStub {
016:
017: /**
018: * The name of the status label. Use this for the test scenario to check the status of an applet.
019: */
020: public static final String APPLET_STATUS_NAME = "AppletStatus";
021:
022: private final AbstractAppletTag fAppletTag;
023: private final Frame fFrame;
024: private final Applet fApplet;
025: private final com.canoo.webtest.extension.applet.runner.Context fAppletContext;
026: private boolean fIsActive;
027:
028: AbstractAppletStub(final Context context, final Applet applet,
029: final AbstractAppletTag appletTag, final Frame frame,
030: final String baseWindowName) {
031: fAppletTag = appletTag;
032: applet.setStub(this );
033: fApplet = applet;
034: fFrame = frame;
035: fAppletContext = context;
036: fFrame.setTitle("Webtest - " + baseWindowName + " - "
037: + applet.getName());
038: }
039:
040: public AppletContext getAppletContext() {
041: return fAppletContext;
042: }
043:
044: public Frame getRootFrame() {
045: return fFrame;
046: }
047:
048: Dimension getAppletDimension() {
049: String widthS = fAppletTag.getWidth();
050: int last = widthS.length();
051: if (widthS.endsWith("%")) {
052: last--;
053: }
054: int width = Integer.parseInt(widthS.substring(0, last));
055:
056: String heightS = fAppletTag.getHeight();
057: last = heightS.length();
058: if (heightS.endsWith("%")) {
059: last--;
060: }
061: int height = Integer.parseInt(heightS.substring(0, last));
062: return new Dimension(width, height);
063: }
064:
065: public abstract void showStatus(String status);
066:
067: void show() {
068: fFrame.show();
069: }
070:
071: public void appletResize(int width, int height) {
072: fFrame.setSize(width, height);
073: }
074:
075: public URL getDocumentBase() {
076: return fAppletTag.getBase();
077: }
078:
079: public URL getCodeBase() {
080: return fAppletTag.getCodebase();
081: }
082:
083: public String getParameter(String name) {
084: return fAppletTag.getParameter(name);
085: }
086:
087: public boolean isActive() {
088: return fIsActive;
089: }
090:
091: void init() {
092: fApplet.init();
093: }
094:
095: void start() {
096: fIsActive = true;
097: fApplet.start();
098: }
099:
100: void stop() {
101: fApplet.stop();
102: fIsActive = false;
103: }
104:
105: void destroy() {
106: fApplet.destroy();
107: }
108:
109: Applet getApplet() {
110: return fApplet;
111: }
112: }
|