001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.harmony.tools.appletviewer;
019:
020: import java.net.MalformedURLException;
021: import java.net.URL;
022: import java.util.HashMap;
023:
024: import javax.swing.JLabel;
025:
026: public class AppletInfo {
027: private static final int DEFAULT_WIDTH = 300;
028: private static final int DEFAULT_HEIGHT = 200;
029:
030: private URL documentBase;
031: private URL codeBase;
032: private URL archive;
033: private String archiveStr;
034: private String tagName;
035: private int width;
036: private int height;
037: private HashMap<String, String> params;
038: private JLabel statusLabel = null;
039:
040: public AppletInfo() {
041: params = new HashMap<String, String>();
042: }
043:
044: public URL getDocumentBase() {
045: return documentBase;
046: }
047:
048: public void setDocumentBase(URL documentBase) {
049: this .documentBase = documentBase;
050: }
051:
052: public URL getCodeBase() {
053: return codeBase;
054: }
055:
056: public void setCodeBase(URL codeBase) {
057: this .codeBase = codeBase;
058: }
059:
060: public void setCodeBase(String codeBaseStr)
061: throws MalformedURLException {
062: this .codeBase = new URL(this .documentBase,
063: (codeBaseStr == null) ? "./" : codeBaseStr);
064: }
065:
066: public URL getArchive() {
067: if (archive == null && archiveStr != null) {
068: try {
069: archive = new URL(getCodeBase(), archiveStr);
070: } catch (MalformedURLException _) {
071: }
072: }
073: return archive;
074: }
075:
076: public void setArchive(URL archive) {
077: this .archive = archive;
078: }
079:
080: public String getParameter(String name) {
081: return params.get(name.toUpperCase());
082: }
083:
084: public void setParameter(String name, String value) {
085: params.put(name.toUpperCase(), value);
086: }
087:
088: public int getWidth() {
089: return width;
090: }
091:
092: public void setWidth(int width) {
093: this .width = width;
094: }
095:
096: public void setWidth(String widthStr) {
097: this .width = (widthStr == null) ? DEFAULT_WIDTH : Integer
098: .parseInt(widthStr);
099: }
100:
101: public int getHeight() {
102: return height;
103: }
104:
105: public void setHeight(int height) {
106: this .height = height;
107: }
108:
109: public void setHeight(String heightStr) {
110: this .height = (heightStr == null) ? DEFAULT_HEIGHT : Integer
111: .parseInt(heightStr);
112: }
113:
114: public void setStatusLabel(JLabel statusLabel) {
115: this .statusLabel = statusLabel;
116: }
117:
118: public void setStatus(String text) {
119: if (statusLabel != null)
120: statusLabel.setText(text);
121: }
122:
123: public URL[] getClassLoaderURLs() {
124: archiveStr = getParameter("ARCHIVE");
125: URL[] res = (archive == null && archiveStr == null) ? new URL[1]
126: : new URL[2];
127: switch (res.length) {
128: case 2:
129: res[1] = getArchive();
130: case 1:
131: res[0] = getCodeBase();
132: }
133: return res;
134: }
135:
136: public void setTag(String tagName) {
137: this .tagName = tagName;
138: }
139:
140: public String getTag() {
141: return tagName;
142: }
143: }
|