home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-01-27 | 4.2 KB | 155 lines |
- /*
- * @(#)MDialogPeer.java 1.11 96/04/24 Sami Shaio
- *
- * Copyright (c) 1995 Sun Microsystems, Inc. All Rights Reserved.
- *
- * Permission to use, copy, modify, and distribute this software
- * and its documentation for NON-COMMERCIAL purposes and without
- * fee is hereby granted provided that this copyright notice
- * appears in all copies. Please refer to the file "copyright.html"
- * for further important copyright and licensing information.
- *
- * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
- * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
- * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
- * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
- * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
- * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
- */
- package sun.awt.win32;
-
- import java.util.Vector;
- import java.awt.*;
- import java.awt.peer.*;
-
- class MDialogPeer extends MPanelPeer implements DialogPeer {
- Insets insets = new Insets(0, 0, 0, 0);
-
- static Vector allDialogs = new Vector();
-
- native void create(MComponentPeer parent);
- native void pSetTitle(String title);
- native void pShow();
- native void pHide();
- native void pReshape(int x, int y, int width, int height);
- native void pDispose();
- // XXX: need separate call to set insets because the insets data member
- // isn't set until after the super constructor is called. This was solved
- // differently on the Motif side but this solution seems cleaner.
- native void setInsets(Insets i);
- public native void setResizable(boolean resizable);
-
- MDialogPeer(Dialog target) {
- super(target);
- // see comment above for setInsets
- setInsets(insets);
- allDialogs.addElement(this);
- if (target.getTitle() != null) {
- pSetTitle(target.getTitle());
- }
- Font f = target.getFont();
- if (f == null) {
- f = new Font("Dialog", Font.BOLD, 10);
- target.setFont(f);
- setFont(f);
- }
- Color c = target.getBackground();
- if (c == null) {
- target.setBackground(Color.lightGray);
- setBackground(Color.lightGray);
- }
- c = target.getForeground();
- if (c == null) {
- target.setForeground(Color.black);
- setForeground(Color.black);
- }
- setResizable(target.isResizable());
- }
-
- public void setTitle(String title) {
- pSetTitle(title);
- }
-
- public void dispose() {
- allDialogs.removeElement(this);
- super.dispose();
- }
-
- /**
- * Called to inform the Dialog that it has moved.
- */
- public synchronized void handleMoved(int x, int y) {
- target.postEvent(new Event(target, 0, Event.WINDOW_MOVED, x, y, 0, 0));
- }
-
-
- public void handleQuit() {
- target.postEvent(new Event(target, Event.WINDOW_DESTROY, null));
- }
-
- public void handleIconify() {
- target.postEvent(new Event(target, Event.WINDOW_ICONIFY, null));
- }
-
- public void handleDeiconify() {
- target.postEvent(new Event(target, Event.WINDOW_DEICONIFY, null));
- }
-
- public void show() {
- if (((Dialog)target).isModal()) {
- ModalThread mt = new ModalThread(this);
- synchronized(mt) {
- try {
- mt.start();
- mt.wait();
- } catch (InterruptedException e) {
- }
- }
- } else {
- pShow();
- }
- }
-
- public void toFront() {
- pShow();
- }
- public void toBack() {
- }
-
- public Insets insets() {
- return insets;
- }
-
- /**
- * Called to inform the Dialog that its size has changed and it
- * should layout its children.
- */
- public synchronized void handleResize(int width, int height) {
- //target.resize(width, height);
- target.invalidate();
- target.validate();
- target.repaint();
- }
- }
-
- /*
- * We must use a separate thread to post the modal dialog, else
- * there is the potential for the modal loop to do event handling
- * with unsecure classes on the call stack. For Win32, this also
- * implements a blocking show() required for a modal dialog.
- */
- class ModalThread extends Thread {
- MDialogPeer d;
-
- public ModalThread(MDialogPeer d) {
- super("AWT-Modal");
- this.d = d;
- }
- public void run() {
- synchronized(this) {
- d.pShow();
- notifyAll();
- }
- }
- }
-