home *** CD-ROM | disk | FTP | other *** search
- package netscape.application;
-
- import java.applet.Applet;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Dialog;
- import java.awt.Dimension;
- import java.awt.Frame;
- import java.awt.Insets;
- import java.awt.MenuBar;
- import java.awt.Point;
- import java.awt.Rectangle;
- import java.awt.Toolkit;
- import netscape.util.InconsistencyException;
-
- public class ExternalWindow implements Window, ApplicationObserver {
- java.awt.Window awtWindow;
- private FoundationPanel panel;
- private WindowOwner owner;
- private int type;
- private Size minimumSize;
- private String title;
- private Rect bounds;
- private boolean resizable;
- private boolean visible;
- private boolean hideOnPause;
- private boolean showOnResume;
- private boolean containsDocument;
- private boolean waitingForInvalidation;
- Menu menu;
- MenuView menuView;
- static final String AWTWINDOW_KEY = "awtWindow";
- static final String PANEL_KEY = "panel";
- static final String OWNER_KEY = "owner";
- static final String TYPE_KEY = "type";
- static final String MINSIZE_KEY = "minimumSize";
- static final String MENU_KEY = "menu";
- static final String HIDEONPAUSE_KEY = "hideOnPause";
- static final String CONTAINS_DOCUMENT_KEY = "containsDocument";
-
- public ExternalWindow() {
- this(1);
- }
-
- private Frame firstRootViewParentFrame() {
- Application var1 = Application.application();
- if (var1 != null) {
- RootView var2 = var1.firstRootView();
- if (var2 != null) {
- FoundationPanel var3 = var2.panel();
-
- Container var4;
- for(var4 = ((Component)var3).getParent(); var4 != null && !(var4 instanceof Frame); var4 = ((Component)var4).getParent()) {
- }
-
- if (var4 != null) {
- return (Frame)var4;
- }
- }
- }
-
- return this.appletParentFrame();
- }
-
- private Frame appletParentFrame() {
- Applet var1 = AWTCompatibility.awtApplet();
- if (var1 == null) {
- return null;
- } else {
- Container var2;
- for(var2 = ((Component)var1).getParent(); var2 != null && !(var2 instanceof Frame); var2 = ((Component)var2).getParent()) {
- }
-
- return (Frame)var2;
- }
- }
-
- private synchronized void validateAWTWindow(int var1, boolean var2) {
- if (this.waitingForInvalidation) {
- this.waitingForInvalidation = false;
- }
-
- if (this.awtWindow == null) {
- Application.application();
- this.panel.rootView();
- if (var2) {
- FoundationDialog var3 = this.createDialog();
- var3.setExternalWindow(this);
- this.awtWindow = var3;
- } else if (var1 == 1) {
- FoundationFrame var4 = this.createFrame();
- var4.setExternalWindow(this);
- this.awtWindow = var4;
- } else {
- FoundationWindow var5 = this.createWindow();
- var5.setExternalWindow(this);
- this.awtWindow = var5;
- }
-
- if (this.awtWindow instanceof Dialog) {
- ((Dialog)this.awtWindow).setResizable(this.resizable);
- } else if (this.awtWindow instanceof FoundationFrame) {
- ((FoundationFrame)this.awtWindow).setResizable(this.resizable);
- }
-
- this.awtWindow.addNotify();
- this.awtWindow.add(this.panel);
- this.awtWindow.reshape(this.bounds.x, this.bounds.y, this.bounds.width, this.bounds.height);
- this.awtWindow.layout();
- if (var1 == 1) {
- if (this.awtWindow instanceof Dialog) {
- ((Dialog)this.awtWindow).setTitle(this.title);
- } else {
- ((FoundationFrame)this.awtWindow).setTitle(this.title);
- }
- }
-
- if (this.menu != null) {
- ((FoundationFrame)this.awtWindow).setMenuBar(this.menu.awtMenuBar());
- }
- }
-
- }
-
- synchronized void invalidateAWTWindow() {
- if (this.waitingForInvalidation) {
- this._invalidateAWTWindow();
- }
-
- this.waitingForInvalidation = false;
- }
-
- void _invalidateAWTWindow() {
- if (this.awtWindow != null) {
- this.bounds = this.bounds();
- this.awtWindow.remove(this.panel);
- this.awtWindow.dispose();
- this.awtWindow = null;
- }
-
- }
-
- public ExternalWindow(int var1) {
- this.resizable = true;
- this.visible = false;
- this.hideOnPause = true;
- this.showOnResume = false;
- this.containsDocument = false;
- this.waitingForInvalidation = false;
- Application.application();
- this.title = "";
- this.type = var1;
- this.panel = this.createPanel();
- this.bounds = new Rect(0, 0, 0, 0);
- this.setBounds(0, 0, 150, 150);
- Application.application().addObserver(this);
- }
-
- public void setTitle(String var1) {
- if (var1 == null) {
- var1 = "";
- }
-
- this.title = var1;
- if (this.awtWindow != null && this.type == 1) {
- if (this.awtWindow instanceof Dialog) {
- ((Dialog)this.awtWindow).setTitle(this.title);
- return;
- }
-
- ((FoundationFrame)this.awtWindow).setTitle(this.title);
- }
-
- }
-
- public String title() {
- return this.title;
- }
-
- public void show() {
- this.validateAWTWindow(this.type, false);
- if (this.owner == null || this.owner.windowWillShow(this)) {
- this.awtWindow.show();
- this.panel.rootView.setVisible(true);
- this.visible = true;
- this.showOnResume = false;
- this.awtWindow.toFront();
- if (this.owner != null) {
- this.owner.windowDidShow(this);
- }
- }
-
- }
-
- public void showModally() {
- Application var1 = Application.application();
- EventLoop var3 = Application.application().eventLoop();
- if (this.type == 0) {
- throw new InconsistencyException("Cannot run blank windows modally");
- } else {
- if (this.owner == null || this.owner.windowWillShow(this)) {
- this.validateAWTWindow(this.type, true);
- ModalDialogManager var4 = new ModalDialogManager((Dialog)this.awtWindow);
- var4.show();
- this.showOnResume = false;
- this.panel.rootView.setVisible(true);
- this.visible = true;
- if (this.owner != null) {
- this.owner.windowDidShow(this);
- }
-
- var1.beginModalSessionForView(this.rootView());
- var1.drawAllDirtyViews();
-
- while(this.isVisible()) {
- Event var2 = var3.getNextEvent();
-
- try {
- var3.processEvent(var2);
- } catch (Exception var6) {
- System.err.println("Uncaught Exception.");
- ((Throwable)var6).printStackTrace(System.err);
- System.err.println("Restarting modal EventLoop.");
- }
- }
-
- var1.endModalSessionForView(this.rootView());
- }
-
- }
- }
-
- public void hide() {
- if (this.awtWindow != null) {
- if (this.owner == null || this.owner.windowWillHide(this)) {
- if (this.containsDocument() && this.isCurrentDocument()) {
- Application.application().chooseNextCurrentDocumentWindow(this);
- }
-
- this.awtWindow.hide();
- this.visible = false;
- this.panel.rootView.setVisible(false);
- this.showOnResume = false;
- if (this.owner != null) {
- this.owner.windowDidHide(this);
- }
-
- WindowInvalidationAgent var1 = new WindowInvalidationAgent(this);
- this.waitingForInvalidation = true;
- var1.run();
- }
-
- }
- }
-
- public boolean isVisible() {
- return this.visible;
- }
-
- public void dispose() {
- RootView var1 = this.rootView();
- Application var2 = var1.application();
- if (this.containsDocument() && this.isCurrentDocument()) {
- var2.chooseNextCurrentDocumentWindow(this);
- }
-
- this.visible = false;
- this._invalidateAWTWindow();
- var2.removeObserver(this);
- var2.removeRootView(var1);
- this.panel.rootView.setVisible(false);
- this.panel.rootView = null;
- }
-
- public void setMenu(Menu var1) {
- this.menu = var1;
- if (!this.menu.isTopLevel()) {
- throw new InconsistencyException("menu must be main menu");
- } else {
- this.menu.setApplication(this.rootView().application());
- MenuBar var2 = this.menu.awtMenuBar();
- if (this.awtWindow != null) {
- ((FoundationFrame)this.awtWindow).setMenuBar(var2);
- }
-
- }
- }
-
- public Menu menu() {
- return this.menu;
- }
-
- public void setMenuView(MenuView var1) {
- if (var1 == null || var1 != this.menuView) {
- if (this.menuView != null) {
- this.menuView.removeFromSuperview();
- }
-
- this.menuView = var1;
- int var2 = this.rootView().bounds.x;
- int var3 = this.rootView().bounds.y;
- int var4 = this.rootView().bounds.width;
- int var5 = this.menuView.height();
- this.menuView.setBounds(var2, var3, var4, var5);
- this.addSubview(this.menuView);
- }
- }
-
- public MenuView menuView() {
- return this.menuView;
- }
-
- public RootView rootView() {
- return this.panel.rootView;
- }
-
- Application application() {
- return Application.application();
- }
-
- public void setOwner(WindowOwner var1) {
- this.owner = var1;
- }
-
- public WindowOwner owner() {
- return this.owner;
- }
-
- void didBecomeMain() {
- if (this.owner != null) {
- this.owner.windowDidBecomeMain(this);
- }
-
- if (this.containsDocument()) {
- Application.application().makeCurrentDocumentWindow(this);
- }
-
- }
-
- void didResignMain() {
- if (this.owner != null) {
- this.owner.windowDidResignMain(this);
- }
-
- }
-
- public Size contentSize() {
- RootView var1 = this.rootView();
- return var1 == null ? null : new Size(var1.bounds.width, var1.bounds.height);
- }
-
- public void addSubview(View var1) {
- RootView var2 = this.rootView();
- if (var2 != null) {
- ((View)var2).addSubview(var1);
- }
-
- }
-
- public void setBounds(int var1, int var2, int var3, int var4) {
- boolean var5 = false;
- if (this.owner != null && (this.bounds.width != var3 || this.bounds.height != var4)) {
- Size var6 = new Size(var3 - this.bounds.width, var4 - this.bounds.height);
- this.owner.windowWillSizeBy(this, var6);
- var3 = this.bounds.width + var6.width;
- var4 = this.bounds.height + var6.height;
- }
-
- if (this.bounds.x != var1 || this.bounds.y != var2 || this.bounds.width != var3 || this.bounds.height != var4) {
- if (this.bounds.width != var3 || this.bounds.height != var4) {
- var5 = true;
- }
-
- this.bounds.setBounds(var1, var2, var3, var4);
- if (this.awtWindow != null) {
- this.awtWindow.reshape(var1, var2, var3, var4);
- Rectangle var7 = this.awtWindow.bounds();
- this.bounds.setBounds(var7.x, var7.y, var7.width, var7.height);
- this.awtWindow.layout();
- }
- }
-
- if (var5 && this.awtWindow == null) {
- this.validateAWTWindow(this.type, false);
- this._invalidateAWTWindow();
- }
-
- }
-
- void validateBounds() {
- if (this.awtWindow != null) {
- Point var2 = this.awtWindow.location();
- Dimension var3 = this.awtWindow.size();
- Rect var1 = new Rect(var2.x, var2.y, var3.width, var3.height);
- if (!var1.equals(this.bounds)) {
- Size var4 = new Size(var1.width - this.bounds.width, var1.height - this.bounds.height);
- if (this.owner != null) {
- this.owner.windowWillSizeBy(this, var4);
- }
-
- this.bounds.setBounds(var1.x, var1.y, var1.width, var1.height);
- }
- }
-
- }
-
- public void setBounds(Rect var1) {
- this.setBounds(var1.x, var1.y, var1.width, var1.height);
- }
-
- public void sizeTo(int var1, int var2) {
- this.setBounds(this.bounds.x, this.bounds.y, var1, var2);
- }
-
- public void sizeBy(int var1, int var2) {
- this.setBounds(this.bounds.x, this.bounds.y, this.bounds.width + var1, this.bounds.height + var2);
- }
-
- public void moveBy(int var1, int var2) {
- this.setBounds(this.bounds.x + var1, this.bounds.y + var2, this.bounds.width, this.bounds.height);
- }
-
- public void center() {
- Dimension var1 = Toolkit.getDefaultToolkit().getScreenSize();
- Rect var2 = new Rect(this.bounds());
- var2.x = (int)Math.floor((double)(var1.width - var2.width) / (double)2.0F);
- var2.y = (int)Math.floor((double)(var1.height - var2.height) / (double)2.0F);
- this.setBounds(var2);
- }
-
- public void moveTo(int var1, int var2) {
- this.setBounds(var1, var2, this.bounds.width, this.bounds.height);
- }
-
- public Size windowSizeForContentSize(int var1, int var2) {
- boolean var4 = this.awtWindow != null;
- if (!var4) {
- this.validateAWTWindow(this.type, false);
- }
-
- Insets var3 = this.awtWindow.insets();
- if (!var4) {
- this._invalidateAWTWindow();
- }
-
- return new Size(var1 + var3.left + var3.right, var2 + var3.top + var3.bottom);
- }
-
- public View viewForMouse(int var1, int var2) {
- return this.rootView().viewForMouse(var1, var2);
- }
-
- public void setMinSize(int var1, int var2) {
- this.minimumSize = new Size(var1, var2);
- }
-
- public Size minSize() {
- return this.minimumSize;
- }
-
- public Rect bounds() {
- if (this.awtWindow != null) {
- Point var1 = this.awtWindow.location();
- Dimension var2 = this.awtWindow.size();
- return new Rect(var1.x, var1.y, var2.width, var2.height);
- } else {
- return new Rect(this.bounds);
- }
- }
-
- public void setResizable(boolean var1) {
- this.resizable = var1;
- if (this.awtWindow != null) {
- throw new InconsistencyException("Cannot call setResizable on a visible external window");
- }
- }
-
- public boolean isResizable() {
- return this.resizable;
- }
-
- public FoundationPanel panel() {
- return this.panel;
- }
-
- public void setContainsDocument(boolean var1) {
- this.containsDocument = var1;
- if (!var1 && Application.application().currentDocumentWindow() == this) {
- Application.application().chooseNextCurrentDocumentWindow(this);
- } else {
- if (var1 && Application.application().firstRootView() == this.rootView()) {
- Application.application().makeCurrentDocumentWindow(this);
- }
-
- }
- }
-
- public boolean containsDocument() {
- return this.containsDocument;
- }
-
- public void didBecomeCurrentDocument() {
- }
-
- public void didResignCurrentDocument() {
- }
-
- public boolean isCurrentDocument() {
- return Application.application().currentDocumentWindow() == this;
- }
-
- protected FoundationDialog createDialog() {
- return new FoundationDialog(this.firstRootViewParentFrame(), true);
- }
-
- protected FoundationFrame createFrame() {
- return new FoundationFrame();
- }
-
- protected FoundationWindow createWindow() {
- return new FoundationWindow(this.appletParentFrame());
- }
-
- protected FoundationPanel createPanel() {
- return new FoundationPanel();
- }
-
- public void applicationDidStart(Application var1) {
- }
-
- public void applicationDidStop(Application var1) {
- this.dispose();
- }
-
- public void focusDidChange(Application var1, View var2) {
- }
-
- public void currentDocumentDidChange(Application var1, Window var2) {
- }
-
- public void applicationDidPause(Application var1) {
- if (this.hideOnPause && this.visible) {
- this.hide();
- this.showOnResume = true;
- }
-
- }
-
- public void applicationDidResume(Application var1) {
- if (this.showOnResume) {
- this.show();
- }
-
- }
-
- public void setHidesWhenPaused(boolean var1) {
- this.hideOnPause = var1;
- }
-
- public boolean hidesWhenPaused() {
- return this.hideOnPause;
- }
-
- public void performCommand(String var1, Object var2) {
- if ("show".equals(var1)) {
- this.show();
- } else if ("hide".equals(var1)) {
- this.hide();
- } else {
- throw new NoSuchMethodError("unknown command: " + var1);
- }
- }
-
- public void moveToFront() {
- if (this.isVisible()) {
- this.awtWindow.toFront();
- }
- }
-
- public void moveToBack() {
- if (this.isVisible()) {
- this.awtWindow.toBack();
- }
- }
- }
-