home *** CD-ROM | disk | FTP | other *** search
- package netscape.constructor;
-
- import java.io.BufferedInputStream;
- import java.io.BufferedOutputStream;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.net.URL;
- import netscape.application.Application;
- import netscape.application.Color;
- import netscape.application.ExtendedTarget;
- import netscape.application.ExternalWindow;
- import netscape.application.InternalWindow;
- import netscape.application.Rect;
- import netscape.application.RootView;
- import netscape.application.Size;
- import netscape.application.Target;
- import netscape.application.View;
- import netscape.util.Archive;
- import netscape.util.Archiver;
- import netscape.util.ClassInfo;
- import netscape.util.Codable;
- import netscape.util.CodingException;
- import netscape.util.Decoder;
- import netscape.util.DeserializationException;
- import netscape.util.Encoder;
- import netscape.util.Enumeration;
- import netscape.util.Hashtable;
- import netscape.util.Unarchiver;
- import netscape.util.Vector;
-
- public class Plan implements ExtendedTarget, Codable, Cloneable {
- Archive archiveData;
- TargetProxyManager targetProxyManager;
- Hashtable nameToComponent;
- Hashtable objectToBounds;
- Vector rootComponents;
- Vector components;
- int versionNumber;
- Size documentSize;
- String planURL;
- int archiveFormat;
- boolean validArchive;
- boolean validObjects;
- Color backgroundColor;
- public static final int UNKNOWN_TYPE = 0;
- public static final int ASCII_TYPE = 1;
- public static final int BINARY_TYPE = 2;
- public static final String ASCII_FILE_EXTENSION = "plana";
- public static final String BINARY_FILE_EXTENSION = "planb";
- public static final String NAME_TO_COMPONENT_KEY = "nameToComponent";
- public static final String OBJECT_TO_BOUNDS_KEY = "objectToBounds";
- public static final String ROOT_COMPONENTS_KEY = "rootComponents";
- public static final String ALL_COMPONENTS_KEY = "allComponents";
- public static final String VERSION_NUMBER_KEY = "versionNumber";
- public static final String DOCUMENT_SIZE_KEY = "documentSize";
- public static final String BACKGROUND_COLOR_KEY = "backgroundColor";
- public static final int CURRENT_VERSION_NUMBER = 2;
-
- public static Plan createPlan(String var0) {
- Plan var1;
- try {
- var1 = new Plan(var0);
- } catch (IOException var2) {
- var1 = null;
- }
-
- return var1;
- }
-
- public static Plan createPlan(String var0, Hashtable var1) {
- Plan var2;
- try {
- var2 = new Plan(var0, var1);
- } catch (IOException var3) {
- var2 = null;
- }
-
- return var2;
- }
-
- public static Plan createPlan(String var0, Target var1) {
- Plan var2;
- try {
- var2 = new Plan(var0, var1);
- } catch (IOException var3) {
- var2 = null;
- }
-
- return var2;
- }
-
- public static Plan createPlan(InputStream var0, int var1) {
- Plan var2;
- try {
- var2 = new Plan(var0, var1);
- } catch (IOException var3) {
- var2 = null;
- }
-
- return var2;
- }
-
- public Plan() {
- this.archiveData = null;
- this.targetProxyManager = null;
- this.nameToComponent = null;
- this.objectToBounds = null;
- this.rootComponents = null;
- this.components = null;
- this.documentSize = null;
- this.validArchive = false;
- this.validObjects = false;
- this.planURL = null;
- this.versionNumber = 2;
- this.archiveFormat = 0;
- this.backgroundColor = Color.lightGray;
- }
-
- public Plan(String var1) throws IOException {
- this.validArchive = false;
- this.validObjects = false;
- if (var1 != null && var1.length() >= 1) {
- InputStream var2 = this.streamFromURL(var1);
- this.initFrom(var2, this.archiveFormat);
- this.planURL = new String(var1);
- if (this.validArchive) {
- this.unarchiveObjects();
- }
-
- }
- }
-
- public Plan(String var1, Hashtable var2) throws IOException {
- this.validArchive = false;
- this.validObjects = false;
- if (var1 != null && var1.length() >= 1) {
- InputStream var3 = this.streamFromURL(var1);
- this.initFrom(var3, this.archiveFormat);
- this.planURL = new String(var1);
- if (this.validArchive) {
- this.unarchiveObjects(var2);
- }
-
- }
- }
-
- public Plan(String var1, Target var2) throws IOException {
- this.validArchive = false;
- this.validObjects = false;
- if (var1 != null && var1.length() >= 1) {
- InputStream var3 = this.streamFromURL(var1);
- this.initFrom(var3, this.archiveFormat);
- this.planURL = new String(var1);
- if (this.validArchive) {
- this.unarchiveObjects(var2);
- }
-
- }
- }
-
- public Plan(InputStream var1, int var2) throws IOException {
- this.initFrom(var1, var2);
- }
-
- protected void initFrom(InputStream var1, int var2) throws IOException {
- this.archiveFormat = var2;
- this.validArchive = false;
- this.validObjects = false;
- this.planURL = null;
- this.versionNumber = 2;
- if (var1 != null) {
- this.archiveData = this.archiveFromStream(var1, var2);
- if (this.archiveData != null) {
- this.validArchive = true;
- }
-
- }
- }
-
- public void releaseObjects() {
- this.targetProxyManager = null;
- this.nameToComponent = null;
- this.objectToBounds = null;
- this.rootComponents = null;
- this.components = null;
- this.documentSize = null;
- this.validObjects = false;
- }
-
- public boolean unarchiveObjects(Hashtable var1) {
- this.validObjects = false;
- if (!this.validArchive) {
- return this.validObjects;
- } else {
- this.validObjects = this.unarchiveFrom(this.archiveData, var1);
- if (this.validObjects) {
- this.finishUnarchiving();
- }
-
- return this.validObjects;
- }
- }
-
- public boolean unarchiveObjects(Target var1) {
- Hashtable var2 = new Hashtable(1);
- var2.put("__nEdEtCoDe", var1);
- return this.unarchiveObjects(var2);
- }
-
- public boolean unarchiveObjects() {
- return this.unarchiveObjects((Hashtable)null);
- }
-
- protected void finishUnarchiving() {
- int var1 = this.rootComponents().count();
-
- while(true) {
- --var1;
- if (var1 < 0) {
- return;
- }
-
- if (this.rootComponents().elementAt(var1) instanceof Script) {
- Script var2 = (Script)this.rootComponents().elementAt(var1);
- if (var2.isUsingLiveConnect()) {
- var2.setNamedObjects(this.nameToComponent());
- }
- }
- }
- }
-
- public TargetProxyManager targetProxyManager() {
- if (this.targetProxyManager == null) {
- this.targetProxyManager = new TargetProxyManager();
- }
-
- return this.targetProxyManager;
- }
-
- public void setTargetProxyManager(TargetProxyManager var1) {
- this.targetProxyManager = var1;
- }
-
- public Hashtable nameToComponent() {
- if (this.nameToComponent == null) {
- this.nameToComponent = new Hashtable();
- }
-
- return this.nameToComponent;
- }
-
- public void setNameToComponent(Hashtable var1) {
- this.nameToComponent = (Hashtable)var1.clone();
- }
-
- public Object componentNamed(String var1) {
- return this.nameToComponent().get(var1);
- }
-
- public Hashtable objectToBounds() {
- if (this.objectToBounds == null) {
- this.objectToBounds = new Hashtable();
- }
-
- return this.objectToBounds;
- }
-
- public void setObjectToBounds(Hashtable var1) {
- this.objectToBounds = var1;
- }
-
- public Vector rootComponents() {
- if (this.rootComponents == null) {
- this.rootComponents = new Vector();
- }
-
- return this.rootComponents;
- }
-
- public void setRootComponents(Vector var1) {
- this.rootComponents = var1;
- }
-
- public Vector components() {
- if (this.components == null) {
- this.components = new Vector();
- }
-
- return this.components;
- }
-
- public void setComponents(Vector var1) {
- this.components = var1;
- }
-
- public int versionNumber() {
- return this.versionNumber;
- }
-
- public void setVersionNumber(int var1) {
- this.versionNumber = var1;
- }
-
- public Size size() {
- if (this.documentSize == null) {
- this.documentSize = new Size(0, 0);
- }
-
- return this.documentSize;
- }
-
- public void setSize(Size var1) {
- this.documentSize = var1;
- }
-
- public void setSize(int var1, int var2) {
- this.documentSize = new Size(var1, var2);
- }
-
- public String url() {
- return this.planURL;
- }
-
- public void setURL(String var1) {
- this.planURL = var1;
- }
-
- public int archiveFormat() {
- return this.archiveFormat;
- }
-
- public void setArchiveFormat(int var1) {
- this.archiveFormat = var1;
- }
-
- public void setValidArchive(boolean var1) {
- this.validArchive = var1;
- }
-
- public boolean isValidArchive() {
- return this.validArchive;
- }
-
- public void setValidObjects(boolean var1) {
- this.validObjects = var1;
- }
-
- public boolean hasValidObjects() {
- return this.validObjects;
- }
-
- public Archive archiveData() {
- return this.archiveData;
- }
-
- public void setArchiveData(Archive var1) {
- this.archiveData = var1;
- }
-
- public Color backgroundColor() {
- return this.backgroundColor;
- }
-
- public void setBackgroundColor(Color var1) {
- this.backgroundColor = var1;
- }
-
- public boolean save() {
- boolean var2 = false;
- if (this.planURL != null && !this.planURL.equals("") && (this.archiveFormat == 1 || this.archiveFormat == 2)) {
- try {
- BufferedOutputStream var1 = new BufferedOutputStream(new FileOutputStream(this.planURL));
- var2 = this.saveToStream(var1, this.archiveFormat);
- ((OutputStream)var1).close();
- return var2;
- } catch (IOException var4) {
- ((Throwable)var4).printStackTrace(System.err);
- return var2;
- }
- } else {
- return var2;
- }
- }
-
- public boolean saveToStream(OutputStream var1, int var2) {
- if (var1 == null) {
- return false;
- } else if (var2 != 1 && var2 != 2) {
- return false;
- } else {
- Archive var3 = new Archive();
-
- try {
- this.archiveTo(var3);
- if (var2 == 1) {
- var3.writeASCII(var1, true);
- } else {
- var3.write(var1);
- }
-
- return true;
- } catch (IOException var5) {
- ((Throwable)var5).printStackTrace(System.err);
- return false;
- } catch (CodingException var6) {
- ((Throwable)var6).printStackTrace(System.err);
- return false;
- }
- }
- }
-
- protected int archiveFormatOf(String var1) {
- if (var1 != null && var1.length() >= 1) {
- if (var1.endsWith("planb")) {
- return 2;
- } else {
- return var1.endsWith("plana") ? 1 : 0;
- }
- } else {
- return 0;
- }
- }
-
- protected InputStream streamFromURL(String var1) throws IOException {
- BufferedInputStream var2 = null;
- boolean var5 = false;
- boolean var6 = false;
- boolean var7 = false;
- boolean var8 = false;
- String var9 = var1;
- if (var1 != null && var1.length() != 0) {
- int var3 = this.archiveFormatOf(var1);
- if (var3 == 1) {
- var6 = true;
- } else if (var3 == 2) {
- var7 = true;
- } else {
- var8 = true;
- }
-
- do {
- var5 = false;
-
- try {
- URL var15 = new URL(var1);
- var2 = new BufferedInputStream(var15.openStream());
- } catch (IOException var13) {
- try {
- URL var14 = new URL(Application.application().codeBase(), var1);
- var2 = new BufferedInputStream(var14.openStream());
- } catch (IOException var12) {
- try {
- Object var4 = null;
- var2 = new BufferedInputStream(new FileInputStream(var1));
- } catch (IOException var11) {
- if (!var7 && var8) {
- var1 = var9 + "." + "planb";
- var7 = true;
- var5 = true;
- var3 = 2;
- } else {
- if (var6 || !var8) {
- throw var11;
- }
-
- var1 = var9 + "." + "plana";
- var6 = true;
- var5 = true;
- var3 = 1;
- }
- }
- }
- }
- } while(var5);
-
- if (var2 != null) {
- this.setArchiveFormat(var3);
- }
-
- return var2;
- } else {
- return null;
- }
- }
-
- protected Archive archiveFromStream(InputStream var1, int var2) throws IOException {
- if (var1 != null && (var2 == 1 || var2 == 2)) {
- Archive var3 = new Archive();
-
- try {
- if (var2 == 1) {
- var3.readASCII(var1);
- } else {
- if (var2 != 2) {
- return null;
- }
-
- var3.read(var1);
- }
-
- return var3;
- } catch (IOException var5) {
- throw var5;
- } catch (CodingException var6) {
- ((Throwable)var6).printStackTrace(System.err);
- return null;
- } catch (DeserializationException var7) {
- ((Throwable)var7).printStackTrace(System.err);
- return null;
- }
- } else {
- return null;
- }
- }
-
- protected boolean unarchiveFrom(Archive var1, Hashtable var2) {
- if (var1 == null) {
- return false;
- } else {
- Hashtable var5;
- try {
- int[] var4 = var1.rootIdentifiers();
- Unarchiver var3 = new Unarchiver(var1);
- if (var4.length > 1) {
- this.targetProxyManager = (TargetProxyManager)var3.unarchiveIdentifier(var4[1]);
- this.targetProxyManager.setTargets(var2);
- }
-
- var5 = (Hashtable)var3.unarchiveIdentifier(var4[0]);
- } catch (CodingException var7) {
- ((Throwable)var7).printStackTrace(System.err);
- return false;
- }
-
- this.decodeDocumentInformation(var5);
- return true;
- }
- }
-
- protected void decodeDocumentInformation(Hashtable var1) {
- Integer var2 = (Integer)var1.get("versionNumber");
- if (var2 != null) {
- this.versionNumber = var2;
- } else {
- this.versionNumber = 0;
- }
-
- if (this.versionNumber != 2) {
- this.decodeBETADocumentInformation(var1);
- } else {
- this.nameToComponent = (Hashtable)var1.get("nameToComponent");
- this.rootComponents = (Vector)var1.get("rootComponents");
- this.components = (Vector)var1.get("allComponents");
- this.documentSize = (Size)var1.get("documentSize");
- this.objectToBounds = (Hashtable)var1.get("objectToBounds");
- this.backgroundColor = (Color)var1.get("backgroundColor");
- }
- }
-
- protected void decodeBETADocumentInformation(Hashtable var1) {
- String var2 = "components";
- String var3 = "namedComponents";
- String var4 = "documentSize";
- String var5 = "nonViewBounds";
- String var6 = "documentVersion";
- String var7 = "builderComponents";
- Vector var11 = (Vector)var1.get(var2);
- if (var11 == null) {
- System.err.println("Unsupported Plan file format. Could not find " + var2 + " in Hashtable: " + var1);
- } else {
- Integer var12 = (Integer)var1.get(var6);
- if (var12 != null) {
- this.versionNumber = var12;
- } else {
- this.versionNumber = 0;
- }
-
- System.err.println("Upgrading plan file " + this.url() + " from version: " + this.versionNumber + " to: " + 2 + ".");
- this.versionNumber = 2;
- this.rootComponents = (Vector)var1.get(var2);
- this.components = (Vector)var1.get(var7);
- this.documentSize = (Size)var1.get(var4);
- this.objectToBounds = (Hashtable)var1.get(var5);
- this.backgroundColor = Color.lightGray;
- Hashtable var10 = (Hashtable)var1.get(var3);
- if (var10 != null) {
- this.nameToComponent().clear();
- Enumeration var8 = var10.keys();
-
- while(var8.hasMoreElements()) {
- Object var9 = var8.nextElement();
- this.nameToComponent().put((String)var10.get(var9), var9);
- }
- }
-
- }
- }
-
- public void archiveObjectsToArchiveData() {
- this.archiveData = new Archive();
- this.archiveTo(this.archiveData);
- }
-
- protected void archiveTo(Archive var1) {
- Archiver var2 = new Archiver(var1);
- Hashtable var3 = new Hashtable();
- this.encodeDocumentInformation(var3);
-
- try {
- var2.archiveRootObject(var3);
- var2.archiveRootObject(this.targetProxyManager());
- } catch (CodingException var5) {
- ((Throwable)var5).printStackTrace();
- }
- }
-
- protected void encodeDocumentInformation(Hashtable var1) {
- if (this.nameToComponent != null) {
- var1.put("nameToComponent", this.nameToComponent);
- } else {
- var1.put("nameToComponent", new Hashtable());
- }
-
- if (this.objectToBounds != null) {
- var1.put("objectToBounds", this.objectToBounds);
- } else {
- var1.put("objectToBounds", new Hashtable());
- }
-
- if (this.rootComponents != null) {
- var1.put("rootComponents", this.rootComponents);
- } else {
- var1.put("rootComponents", new Vector(0));
- }
-
- if (this.components != null) {
- var1.put("allComponents", this.components);
- } else {
- var1.put("allComponents", new Vector(0));
- }
-
- var1.put("versionNumber", new Integer(this.versionNumber));
- if (this.documentSize != null) {
- var1.put("documentSize", this.documentSize);
- } else {
- var1.put("documentSize", new Size(0, 0));
- }
-
- if (this.backgroundColor != null) {
- var1.put("backgroundColor", this.backgroundColor);
- } else {
- var1.put("backgroundColor", Color.lightGray);
- }
- }
-
- public void performCommand(String var1, Object var2) {
- }
-
- public boolean canPerformCommand(String var1) {
- return false;
- }
-
- public void describeClassInfo(ClassInfo var1) {
- var1.addClass("netscape.constructor.Plan", 2);
- var1.addField("nameToComponent", (byte)18);
- var1.addField("objectToBounds", (byte)18);
- var1.addField("rootComponents", (byte)18);
- var1.addField("allComponents", (byte)18);
- var1.addField("versionNumber", (byte)18);
- var1.addField("documentSize", (byte)18);
- var1.addField("backgroundColor", (byte)18);
- }
-
- public void encode(Encoder var1) throws CodingException {
- var1.encodeObject("nameToComponent", this.nameToComponent);
- var1.encodeObject("objectToBounds", this.objectToBounds);
- var1.encodeObject("rootComponents", this.rootComponents);
- var1.encodeObject("allComponents", this.components);
- var1.encodeObject("versionNumber", new Integer(this.versionNumber));
- var1.encodeObject("documentSize", this.documentSize);
- var1.encodeObject("backgroundColor", this.backgroundColor);
- }
-
- public void decode(Decoder var1) throws CodingException {
- this.nameToComponent = (Hashtable)var1.decodeObject("nameToComponent");
- this.objectToBounds = (Hashtable)var1.decodeObject("objectToBounds");
- this.rootComponents = (Vector)var1.decodeObject("rootComponents");
- this.components = (Vector)var1.decodeObject("allComponents");
- Integer var2 = (Integer)var1.decodeObject("versionNumber");
- if (var2 != null) {
- this.versionNumber = var2;
- } else {
- this.versionNumber = 0;
- }
-
- this.documentSize = (Size)var1.decodeObject("documentSize");
- this.backgroundColor = (Color)var1.decodeObject("backgroundColor");
- }
-
- public void finishDecoding() throws CodingException {
- }
-
- public Object clone() {
- Plan var1 = null;
-
- try {
- var1 = (Plan)super.clone();
- } catch (CloneNotSupportedException var5) {
- System.err.println(var5);
- ((Throwable)var5).printStackTrace();
- }
-
- Hashtable var3 = new Hashtable(1);
- var3.put("__nEdEtCoDeNonReplacing", new Object());
- var1.targetProxyManager = null;
- var1.nameToComponent = null;
- var1.objectToBounds = null;
- var1.rootComponents = null;
- var1.components = null;
- var1.documentSize = null;
- var1.backgroundColor = null;
- Archive var2 = new Archive();
- this.archiveTo(var2);
- var1.unarchiveFrom(var2, var3);
- return var1;
- }
-
- public Rect boundingRect() {
- Rect var2 = null;
- int var1 = this.rootComponents().count();
-
- while(true) {
- --var1;
- if (var1 < 0) {
- if (var2 == null) {
- return new Rect(0, 0, 0, 0);
- }
-
- return var2;
- }
-
- Object var3 = this.rootComponents().elementAt(var1);
- if (var3 instanceof View && this.constructorComponentWasView(var3) && !(var3 instanceof InternalWindow)) {
- if (var2 == null) {
- var2 = new Rect(((View)var3).bounds);
- } else {
- var2.unionWith(((View)var3).bounds);
- }
- }
- }
- }
-
- public void sizeToFit() {
- Rect var1 = this.boundingRect();
- this.moveBy(-var1.x, -var1.y);
- this.setSize(new Size(var1.width, var1.height));
- }
-
- public void moveBy(int var1, int var2) {
- int var3 = this.rootComponents().count();
-
- while(true) {
- --var3;
- if (var3 < 0) {
- return;
- }
-
- Object var4 = this.rootComponents().elementAt(var3);
- if (var4 instanceof View && this.constructorComponentWasView(var4)) {
- ((View)var4).moveBy(var1, var2);
- }
- }
- }
-
- public void addContentsToView(View var1) {
- int var3 = this.rootComponents().count();
-
- for(int var2 = 0; var2 < var3; ++var2) {
- Object var4 = this.rootComponents().elementAt(var2);
- if (var4 instanceof InternalWindow && this.constructorComponentWasView(var4)) {
- InternalWindow var5 = (InternalWindow)var4;
- if (var1 instanceof RootView) {
- var5.setRootView((RootView)var1);
- if (var5.onscreenAtStartup()) {
- var5.show();
- }
- }
- } else if ((this.constructorComponentWasView(var4) || !(var4 instanceof View)) && var4 instanceof View) {
- var1.addSubview((View)var4);
- }
- }
-
- }
-
- protected boolean constructorComponentWasView(Object var1) {
- return !this.objectToBounds.containsKey(var1);
- }
-
- public View viewWithContents() {
- View var1 = new View(0, 0, this.size().width, this.size().height);
- this.addContentsToView(var1);
- return var1;
- }
-
- public InternalWindow internalWindowWithContents() {
- InternalWindow var1 = new InternalWindow();
- Size var2 = var1.windowSizeForContentSize(this.size().width, this.size().height);
- var1.setBounds(0, 0, var2.width, var2.height);
- var1.contentView().setBackgroundColor(this.backgroundColor());
- this.addContentsToView(var1.contentView());
- return var1;
- }
-
- public ExternalWindow externalWindowWithContents() {
- ExternalWindow var1 = new ExternalWindow();
- Size var2 = var1.windowSizeForContentSize(this.size().width, this.size().height);
- var1.setBounds(0, 0, var2.width, var2.height);
- var1.rootView().setColor(this.backgroundColor());
- this.addContentsToView(var1.rootView());
- return var1;
- }
- }
-