home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 25 / CDROM25.iso / Share / prog / VJ11 / VJTRIAL.EXE / IE30Java.exe / classd.exe / sun / awt / win32 / MDialogPeer.java < prev    next >
Encoding:
Java Source  |  1997-01-27  |  4.2 KB  |  155 lines

  1. /*
  2.  * @(#)MDialogPeer.java    1.11 96/04/24 Sami Shaio
  3.  *
  4.  * Copyright (c) 1995 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL purposes and without
  8.  * fee is hereby granted provided that this copyright notice
  9.  * appears in all copies. Please refer to the file "copyright.html"
  10.  * for further important copyright and licensing information.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  13.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  14.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  16.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  17.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  18.  */
  19. package sun.awt.win32;
  20.  
  21. import java.util.Vector;
  22. import java.awt.*;
  23. import java.awt.peer.*;
  24.  
  25. class MDialogPeer extends MPanelPeer implements DialogPeer {
  26.     Insets insets = new Insets(0, 0, 0, 0);
  27.  
  28.     static Vector allDialogs = new Vector();
  29.  
  30.     native void create(MComponentPeer parent);
  31.     native void pSetTitle(String title);
  32.     native void pShow();
  33.     native void pHide();
  34.     native void pReshape(int x, int y, int width, int height);
  35.     native void pDispose();
  36.     // XXX: need separate call to set insets because the insets data member
  37.     // isn't set until after the super constructor is called. This was solved
  38.     // differently on the Motif side but this solution seems cleaner.
  39.     native void setInsets(Insets i);
  40.     public native void setResizable(boolean resizable);
  41.  
  42.     MDialogPeer(Dialog target) {
  43.     super(target);
  44.     // see comment above for setInsets
  45.     setInsets(insets);
  46.     allDialogs.addElement(this);
  47.     if (target.getTitle() != null) {
  48.         pSetTitle(target.getTitle());
  49.     }
  50.     Font f = target.getFont();
  51.     if (f == null) {
  52.         f = new Font("Dialog", Font.BOLD, 10);
  53.         target.setFont(f);
  54.         setFont(f);
  55.     }
  56.     Color c = target.getBackground();
  57.     if (c == null) {
  58.         target.setBackground(Color.lightGray);
  59.         setBackground(Color.lightGray);
  60.     }
  61.     c = target.getForeground();
  62.     if (c == null) {
  63.         target.setForeground(Color.black);
  64.         setForeground(Color.black);
  65.     }
  66.     setResizable(target.isResizable());
  67.     }
  68.  
  69.     public void setTitle(String title) {
  70.     pSetTitle(title);
  71.     }
  72.  
  73.     public void dispose() {
  74.     allDialogs.removeElement(this);
  75.     super.dispose();
  76.     }
  77.  
  78.     /**
  79.      * Called to inform the Dialog that it has moved.
  80.      */
  81.     public synchronized void handleMoved(int x, int y) {
  82.     target.postEvent(new Event(target, 0, Event.WINDOW_MOVED, x, y, 0, 0));
  83.     }
  84.  
  85.  
  86.     public void handleQuit() {
  87.     target.postEvent(new Event(target, Event.WINDOW_DESTROY, null));
  88.     }
  89.  
  90.     public void handleIconify() {
  91.     target.postEvent(new Event(target, Event.WINDOW_ICONIFY, null));
  92.     }
  93.  
  94.     public void handleDeiconify() {
  95.     target.postEvent(new Event(target, Event.WINDOW_DEICONIFY, null));
  96.     }
  97.  
  98.     public void show() {
  99.     if (((Dialog)target).isModal()) {
  100.         ModalThread mt = new ModalThread(this);
  101.         synchronized(mt) {
  102.             try {
  103.                     mt.start();
  104.             mt.wait();
  105.             } catch (InterruptedException e) {
  106.             }
  107.         }
  108.     } else {
  109.         pShow();
  110.      }
  111.     }
  112.  
  113.     public void toFront() {
  114.     pShow();
  115.     }
  116.     public void toBack() {
  117.     }
  118.  
  119.     public Insets insets() {
  120.     return insets;
  121.     }
  122.  
  123.     /**
  124.      * Called to inform the Dialog that its size has changed and it
  125.      * should layout its children.
  126.      */
  127.     public synchronized void handleResize(int width, int height) {
  128.     //target.resize(width, height);
  129.     target.invalidate();
  130.     target.validate();
  131.     target.repaint();
  132.     }
  133. }
  134.  
  135. /*
  136.  * We must use a separate thread to post the modal dialog, else
  137.  * there is the potential for the modal loop to do event handling
  138.  * with unsecure classes on the call stack.  For Win32, this also
  139.  * implements a blocking show() required for a modal dialog.
  140.  */
  141. class ModalThread extends Thread {
  142.     MDialogPeer d;
  143.  
  144.     public ModalThread(MDialogPeer d) {
  145.     super("AWT-Modal");
  146.     this.d = d;
  147.     }
  148.     public void run() {
  149.     synchronized(this) {
  150.             d.pShow();
  151.         notifyAll();
  152.     }
  153.     }
  154. }
  155.