home *** CD-ROM | disk | FTP | other *** search
- package netscape.application;
-
- import java.applet.Applet;
- import java.applet.AppletContext;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Frame;
- import java.awt.MediaTracker;
- import java.awt.Panel;
- import java.io.InputStream;
- import java.net.URL;
- import netscape.util.Enumeration;
- import netscape.util.Hashtable;
- import netscape.util.InconsistencyException;
- import netscape.util.Vector;
-
- public class Application implements Runnable, EventProcessor {
- static Hashtable groupToApplication = new Hashtable();
- static final String _releaseName = "IFC 1.1.1";
- static Clipboard clipboard;
- static Object clipboardLock = new Object();
- Applet applet;
- AppletResources _appResources;
- EventLoop eventLoop = new EventLoop();
- Vector _languageVector;
- Vector rootViews = new Vector();
- RootView mainRootView;
- boolean didCreateApplet;
- Vector _modalVector = new Vector();
- Vector observers = new Vector();
- Vector activeMenuViews = new Vector();
- boolean jdkMouseEventHackEnabled = true;
- MediaTracker tracker;
- int bitmapCount;
- Hashtable bitmapByName = new Hashtable();
- Hashtable soundByName = new Hashtable();
- Hashtable fontByName = new Hashtable();
- DebugGraphicsInfo debugGraphicsInfo;
- TimerQueue timerQueue;
- Object cleanupLock;
- boolean isPaused;
- boolean _kbdUIEnabled = true;
- Window currentDocumentWindow;
- KeyboardArrow keyboardArrow;
- public static final int TOP_LEFT_POSITION = 0;
- public static final int BOTTOM_LEFT_POSITION = 1;
- public static final int TOP_RIGHT_POSITION = 2;
- public static final int BOTTOM_RIGHT_POSITION = 3;
- static final int FIRST_POSITION = 0;
- static final int LAST_POSITION = 3;
- static final int arrowXOffset = 0;
- static final int arrowYOffset = 0;
-
- public Application() {
- groupToApplication.put(Thread.currentThread().getThreadGroup(), this);
- FoundationApplet var1 = FoundationApplet.applet();
- if (var1 == null) {
- var1 = this.createApplet();
- var1.setApplication(this);
- this.didCreateApplet = true;
- } else {
- this.isPaused = true;
- var1.setupCanvas(this);
- }
-
- this.applet = var1;
- this._appResources = new AppletResources(this, this.codeBase());
- this.timerQueue = new TimerQueue();
- this.eventLoop.application = this;
- }
-
- public static String releaseName() {
- return "IFC 1.1.1";
- }
-
- public Application(Applet var1) {
- groupToApplication.put(Thread.currentThread().getThreadGroup(), this);
- this.applet = var1;
- this._appResources = new AppletResources(this, this.codeBase());
- this.timerQueue = new TimerQueue();
- this.appletStarted();
- this.eventLoop.application = this;
- }
-
- public static Application application() {
- ThreadGroup var0 = Thread.currentThread().getThreadGroup();
- Application var1 = (Application)groupToApplication.get(var0);
- if (var1 == null) {
- var1 = FoundationApplet.currentApplication();
- }
-
- return var1;
- }
-
- public void init() {
- }
-
- public void cleanup() {
- Enumeration var1 = groupToApplication.keys();
- this.applicationDidStop();
- if (this.applet instanceof FoundationApplet) {
- ((FoundationApplet)this.applet).cleanup();
- }
-
- if (this.didCreateApplet) {
- ((FoundationApplet)this.applet).destroyFromIFC();
- if (this.applet.getParent() != null) {
- this.applet.getParent().remove(this.applet);
- }
- }
-
- while(var1.hasMoreElements()) {
- ThreadGroup var2 = (ThreadGroup)var1.nextElement();
- Application var3 = (Application)groupToApplication.get(var2);
- if (var3 == this) {
- groupToApplication.remove(var2);
- break;
- }
- }
-
- this.timerQueue = null;
- this.observers.removeAllElements();
- this.eventLoop.application = null;
- }
-
- public void stopRunning() {
- this.eventLoop.stopRunning();
- }
-
- void stopRunningForAWT() {
- Object var1 = this.cleanupLock;
- synchronized(var1){}
-
- try {
- this.eventLoop.stopRunning();
-
- while(true) {
- try {
- this.cleanupLock.wait();
- return;
- } catch (InterruptedException var5) {
- }
- }
- } catch (Throwable var6) {
- throw var6;
- }
- }
-
- public void run() {
- this.cleanupLock = new Object();
- this.applicationDidStart();
- this.init();
- this.eventLoop.run();
- this.cleanup();
- Object var1 = this.cleanupLock;
- synchronized(var1){}
-
- try {
- this.cleanupLock.notify();
- } catch (Throwable var3) {
- throw var3;
- }
-
- }
-
- public EventLoop eventLoop() {
- return this.eventLoop;
- }
-
- Vector languagePreferences() {
- if (this._languageVector == null) {
- this._languageVector = new Vector();
- }
-
- return this._languageVector;
- }
-
- void syncGraphics() {
- }
-
- InputStream streamForInterface(String var1) {
- return this._appResources.streamForInterface(var1);
- }
-
- InputStream streamForResourceOfType(String var1, String var2) {
- return this._appResources.streamForResourceOfType(var1, var2);
- }
-
- public boolean isApplet() {
- return !this.didCreateApplet;
- }
-
- InputStream streamForRelativePath(String var1) {
- URL var2;
- try {
- var2 = new URL(this.codeBase(), var1);
- } catch (Exception var6) {
- System.err.println("Application.streamForRelativePath() - " + var6);
- var2 = null;
- }
-
- if (var2 == null) {
- return null;
- } else {
- InputStream var3;
- try {
- var3 = var2.openStream();
- } catch (Exception var5) {
- System.err.println("Application.streamForURL() - Trouble retrieving URL " + var2 + " : " + var5);
- var3 = null;
- }
-
- return var3;
- }
- }
-
- AppletContext getAppletContext() {
- return this.applet == null ? null : this.applet.getAppletContext();
- }
-
- public URL codeBase() {
- return this.applet.getCodeBase();
- }
-
- public String parameterNamed(String var1) {
- return this.applet == null ? null : this.applet.getParameter(var1);
- }
-
- public RootView mainRootView() {
- return this.mainRootView;
- }
-
- public void setMainRootView(RootView var1) {
- this.addRootView(var1);
- this.mainRootView = var1;
- }
-
- RootView firstRootView() {
- return (RootView)this.rootViews.lastElement();
- }
-
- public Vector rootViews() {
- return this.rootViews;
- }
-
- public Vector externalWindows() {
- int var2 = this.rootViews.count();
- Vector var3 = new Vector();
-
- for(int var1 = 0; var1 < var2; ++var1) {
- RootView var4 = (RootView)this.rootViews.elementAt(var1);
- ExternalWindow var5 = var4.externalWindow();
- if (var5 != null) {
- var3.addElement(var5);
- }
- }
-
- return var3;
- }
-
- void addRootView(RootView var1) {
- if (!this.rootViews.contains(var1)) {
- this.rootViews.insertElementAt(var1, 0);
- var1.setApplication(this);
- }
-
- }
-
- void removeRootView(RootView var1) {
- this.rootViews.removeElement(var1);
- var1.setApplication((Application)null);
- if (this.rootViews.count() > 0) {
- ((RootView)this.rootViews.lastElement()).didBecomeFirstRootView();
- }
-
- }
-
- void makeFirstRootView(RootView var1) {
- if (this.rootViews.indexOf(var1) != -1) {
- if (this.rootViews.lastElement() != var1) {
- RootView var2 = (RootView)this.rootViews.lastElement();
- this.rootViews.removeElement(var1);
- this.rootViews.addElement(var1);
- if (var2 != null) {
- var2.didResignFirstRootView();
- }
-
- var1.didBecomeFirstRootView();
- }
-
- }
- }
-
- Frame frame() {
- Object var1;
- for(var1 = this.applet; var1 != null && !(var1 instanceof Frame); var1 = ((Component)var1).getParent()) {
- }
-
- return var1 != null ? (Frame)var1 : null;
- }
-
- synchronized MediaTracker mediaTracker() {
- if (this.tracker == null) {
- this.tracker = new MediaTracker(this.applet);
- }
-
- return this.tracker;
- }
-
- synchronized int nextBitmapNumber() {
- return this.bitmapCount++;
- }
-
- synchronized TimerQueue timerQueue() {
- return this.timerQueue;
- }
-
- void addActiveMenuView(MenuView var1) {
- this.activeMenuViews.addElementIfAbsent(var1);
- }
-
- void removeActiveMenuView(MenuView var1) {
- this.activeMenuViews.removeElement(var1);
- }
-
- public void willProcessEvent(Event var1) {
- }
-
- void willProcessInternalEvent(Event var1) {
- if (this.activeMenuViews.count() != 0 && var1.type() == -1) {
- MenuView var2 = (MenuView)this.activeMenuViews.lastElement();
- var2.mouseWillDown((MouseEvent)var1);
- }
- }
-
- public void didProcessEvent(Event var1) {
- }
-
- void didProcessInternalEvent(Event var1) {
- this.drawAllDirtyViews();
- }
-
- protected void drawAllDirtyViews() {
- int var2 = this.rootViews.count();
-
- for(int var1 = 0; var1 < var2; ++var1) {
- RootView var3 = (RootView)this.rootViews.elementAt(var1);
- var3.drawDirtyViews();
- var3._updateCursorAndMoveView();
- }
-
- }
-
- boolean isMac() {
- String var1 = System.getProperty("os.name");
- return var1 != null && var1.startsWith("Mac");
- }
-
- public void keyDown(KeyEvent var1) {
- boolean var2 = false;
- RootView var3 = this.firstRootView();
- if (var3 != null) {
- var3.processKeyboardEvent(var1, false);
- }
-
- }
-
- public void keyUp(KeyEvent var1) {
- }
-
- protected void beginModalSessionForView(View var1) {
- if (var1 == null) {
- throw new InconsistencyException("beginModalSessionForView called with null view");
- } else {
- this._modalVector.addElement(var1);
- RootView var2 = var1.rootView();
- if (var2 != null) {
- var2.updateCursor();
- }
-
- }
- }
-
- protected void endModalSessionForView(View var1) {
- if (var1 != this._modalVector.lastElement()) {
- throw new InconsistencyException("endModalSessionForView called for a view that is not the last modal view");
- } else {
- this._modalVector.removeLastElement();
- RootView var2 = var1.rootView();
- if (var2 != null) {
- var2.updateCursor();
- var2.validateSelectedView();
- }
-
- }
- }
-
- public View modalView() {
- return this._modalVector.count() > 0 ? (View)this._modalVector.lastElement() : null;
- }
-
- boolean isModalViewShowing() {
- return this._modalVector.count() != 0;
- }
-
- public void performCommandAndWait(Target var1, String var2, Object var3) {
- CommandEvent var4 = new CommandEvent(var1, var2, var3);
- this.eventLoop.addEventAndWait(var4);
- }
-
- public void performCommandLater(Target var1, String var2, Object var3, boolean var4) {
- CommandEvent var5 = new CommandEvent(var1, var2, var3);
- if (var4) {
- this.eventLoop.filterEvents(new CommandFilter(var5.target, var5.command, var3));
- }
-
- this.eventLoop.addEvent(var5);
- }
-
- public void performCommandLater(Target var1, String var2, Object var3) {
- this.performCommandLater(var1, var2, var3, false);
- }
-
- protected FoundationApplet createApplet() {
- Frame var1 = new Frame();
- FoundationApplet var2 = new FoundationApplet();
- ((Container)var1).add(var2);
- var1.addNotify();
- ((Panel)var2).addNotify();
- ((Applet)var2).setStub(new FoundationAppletStub());
- return var2;
- }
-
- String exceptionHeader() {
- return "Uncaught exception. IFC release: IFC 1.1.1";
- }
-
- public void addObserver(ApplicationObserver var1) {
- this.observers.addElementIfAbsent(var1);
- }
-
- public void removeObserver(ApplicationObserver var1) {
- this.observers.removeElement(var1);
- }
-
- public void appletStarted() {
- int var1 = this.observers.count();
- this.isPaused = false;
-
- while(var1-- > 0) {
- ApplicationObserver var2 = (ApplicationObserver)this.observers.elementAt(var1);
- var2.applicationDidResume(this);
- }
-
- var1 = this.rootViews.count();
-
- while(var1-- > 0) {
- RootView var4 = (RootView)this.rootViews.elementAt(var1);
- if (var4.externalWindow() == null) {
- var4.setVisible(true);
- }
- }
-
- }
-
- public void appletStopped() {
- int var1 = this.observers.count();
- this.isPaused = true;
-
- while(var1-- > 0) {
- ApplicationObserver var2 = (ApplicationObserver)this.observers.elementAt(var1);
- var2.applicationDidPause(this);
- }
-
- var1 = this.rootViews.count();
-
- while(var1-- > 0) {
- RootView var4 = (RootView)this.rootViews.elementAt(var1);
- if (var4.externalWindow() == null) {
- var4.setVisible(false);
- }
- }
-
- }
-
- void applicationDidStart() {
- int var1 = this.observers.count();
-
- while(var1-- > 0) {
- ApplicationObserver var2 = (ApplicationObserver)this.observers.elementAt(var1);
- var2.applicationDidStart(this);
- }
-
- }
-
- void applicationDidStop() {
- int var1 = this.observers.count();
-
- while(var1-- > 0) {
- ApplicationObserver var2 = (ApplicationObserver)this.observers.elementAt(var1);
- var2.applicationDidStop(this);
- }
-
- }
-
- public void processEvent(Event var1) {
- if (var1 instanceof ApplicationEvent) {
- if (var1.type == -26) {
- this.appletStopped();
- return;
- }
-
- if (var1.type == -27) {
- this.appletStarted();
- }
- }
-
- }
-
- public boolean isRunning() {
- return this.eventLoop.isRunning();
- }
-
- public boolean isPaused() {
- return this.isPaused;
- }
-
- static Clipboard clipboard() {
- Object var1 = clipboardLock;
- synchronized(var1){}
-
- Clipboard var0;
- try {
- if (clipboard == null) {
- clipboard = JDK11AirLock.clipboard();
- if (clipboard == null) {
- clipboard = new TextBag();
- }
- }
-
- var0 = clipboard;
- } catch (Throwable var4) {
- throw var4;
- }
-
- return var0;
- }
-
- public void makeCurrentDocumentWindow(Window var1) {
- if (var1 != null && !var1.containsDocument()) {
- throw new InconsistencyException("makeCurrentDocumentWindow: window is not a document");
- } else {
- if (this.currentDocumentWindow != null) {
- this.currentDocumentWindow.didResignCurrentDocument();
- this.currentDocumentWindow = null;
- }
-
- if (var1 != null) {
- this.currentDocumentWindow = var1;
- this.currentDocumentWindow.didBecomeCurrentDocument();
- }
-
- int var2 = this.observers.count();
-
- while(var2-- > 0) {
- ApplicationObserver var3 = (ApplicationObserver)this.observers.elementAt(var2);
-
- try {
- var3.currentDocumentDidChange(this, this.currentDocumentWindow);
- } catch (IncompatibleClassChangeError var4) {
- }
- }
-
- }
- }
-
- public Window currentDocumentWindow() {
- return this.currentDocumentWindow;
- }
-
- public void chooseNextCurrentDocumentWindow(Window var1) {
- Window var2 = null;
- if (var1 != null && !(var1 instanceof ExternalWindow)) {
- if (((InternalWindow)var1).rootView() != null) {
- var2 = this._chooseNextInternalWindowWithDocument(((InternalWindow)var1).rootView(), (InternalWindow)var1);
- }
- } else {
- var2 = this._chooseNextExternalWindowWithDocument((ExternalWindow)var1);
- if (var2 == null && this.mainRootView() != null) {
- var2 = this._chooseNextInternalWindowWithDocument(this.mainRootView(), (InternalWindow)null);
- }
- }
-
- this.makeCurrentDocumentWindow(var2);
- }
-
- Window _chooseNextInternalWindowWithDocument(RootView var1, InternalWindow var2) {
- Vector var3 = var1.internalWindows();
-
- for(int var5 = var3.count() - 1; var5 >= 0; --var5) {
- InternalWindow var4 = (InternalWindow)var3.elementAt(var5);
- if (var4 != var2 && var4.containsDocument()) {
- return var4;
- }
- }
-
- return null;
- }
-
- Window _chooseNextExternalWindowWithDocument(ExternalWindow var1) {
- Vector var2 = this.externalWindows();
-
- for(int var4 = var2.count() - 1; var4 >= 0; --var4) {
- ExternalWindow var3 = (ExternalWindow)var2.elementAt(var4);
- if (var3 != var1 && var3.containsDocument()) {
- return var3;
- }
- }
-
- return null;
- }
-
- void focusChanged(View var1) {
- int var2 = this.observers.count();
-
- while(var2-- > 0) {
- ApplicationObserver var3 = (ApplicationObserver)this.observers.elementAt(var2);
-
- try {
- var3.focusDidChange(this, var1);
- } catch (IncompatibleClassChangeError var4) {
- }
- }
-
- }
-
- KeyboardArrow keyboardArrow() {
- if (this.keyboardArrow == null) {
- this.keyboardArrow = new KeyboardArrow();
- }
-
- return this.keyboardArrow;
- }
-
- public int keyboardArrowPosition(View var1) {
- RootView var2 = var1.rootView();
- Rect var3 = ((View)var2).localBounds();
- new Point();
- Rect var4 = new Rect();
- var1.computeVisibleRect(var4);
- var4.intersectWith(var1.keyboardRect());
- var1.convertRectToView(var2, var4, var4);
-
- for(int var8 = 0; var8 <= 3; ++var8) {
- Image var5 = this.keyboardArrowImage(var8);
- Point var6 = this.keyboardArrowHotSpot(var8);
- Point var7 = this.keyboardArrowLocation(var1, var8);
- var7.x -= var6.x;
- var7.y -= var6.y;
- if (var3.contains(new Rect(var7.x, var7.y, var5.width(), var5.height()))) {
- return var8;
- }
- }
-
- return 0;
- }
-
- public Image keyboardArrowImage(int var1) {
- switch (var1) {
- case 0:
- return Bitmap.bitmapNamed("netscape/application/topLeftArrow.gif");
- case 1:
- return Bitmap.bitmapNamed("netscape/application/bottomLeftArrow.gif");
- case 2:
- return Bitmap.bitmapNamed("netscape/application/topRightArrow.gif");
- case 3:
- return Bitmap.bitmapNamed("netscape/application/bottomRightArrow.gif");
- default:
- return null;
- }
- }
-
- public Point keyboardArrowHotSpot(int var1) {
- switch (var1) {
- case 0:
- return new Point(8, 12);
- case 1:
- return new Point(8, 0);
- case 2:
- return new Point(0, 12);
- case 3:
- return new Point(0, 0);
- default:
- return null;
- }
- }
-
- public Point keyboardArrowLocation(View var1, int var2) {
- RootView var3 = var1.rootView();
- ((View)var3).localBounds();
- Rect var4 = var1.localBounds();
- var4 = new Rect();
- var1.computeVisibleRect(var4);
- var4.intersectWith(var1.keyboardRect());
- if (var4.width != 0 && var4.height != 0) {
- var1.convertRectToView(var1.rootView(), var4, var4);
- switch (var2) {
- case 0:
- return new Point(var4.x, var4.y);
- case 1:
- return new Point(var4.x, var4.y + var4.height);
- case 2:
- return new Point(var4.x + var4.width, var4.y);
- case 3:
- return new Point(var4.x + var4.width, var4.y + var4.height);
- default:
- throw new InconsistencyException("Unknown position " + var2);
- }
- } else {
- return new Point(Integer.MAX_VALUE, Integer.MAX_VALUE);
- }
- }
-
- public void setKeyboardUIEnabled(boolean var1) {
- this._kbdUIEnabled = var1;
- }
-
- public boolean isKeyboardUIEnabled() {
- return this._kbdUIEnabled;
- }
-
- public Applet applet() {
- return this.applet;
- }
-
- public AppletResources appletResources() {
- return this._appResources;
- }
-
- public static String clipboardText() {
- return clipboard().text();
- }
-
- public static void setClipboardText(String var0) {
- clipboard().setText(var0);
- }
-
- public void setHandleJDK11MouseEvents(boolean var1) {
- this.jdkMouseEventHackEnabled = var1;
- }
-
- public boolean handleJDK11MouseEvents() {
- return this.jdkMouseEventHackEnabled;
- }
- }
-