home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / IFC_112 / netscape / application / AWTCompatibility.java < prev    next >
Encoding:
Text File  |  1999-05-28  |  6.3 KB  |  210 lines  |  [TEXT/CWIE]

  1. // AWTCompatibility.java
  2. // By Ned Etcode
  3. // Copyright 1996, 1997 Netscape Communications Corp.  All rights reserved.
  4.  
  5. package netscape.application;
  6.  
  7. import java.awt.image.ImageProducer;
  8.  
  9.  
  10. // ALERT! - How does the new cursor system work with AWT components?
  11.  
  12.  
  13. /** A collection of static methods for conversion between many AWT and IFC
  14.   * primitives.
  15.   * @note 1.0 bitmapForAWT... methods will no longer leak the bitmaps
  16.   * @note 1.0 added api to get the frame for a RootView
  17.   * @note 1.0 added api to get colors from AWT colors & vice versa
  18.   * @note 1.0 added api to get graphics from AWT graphics.
  19.   */
  20. public class AWTCompatibility {
  21.     private AWTCompatibility() {
  22.     }
  23.  
  24.     /** Creates a new Bitmap instance from a java.awt.Image.
  25.       */
  26.     public static Bitmap bitmapForAWTImage(java.awt.Image awtImage) {
  27.         return new Bitmap(awtImage);
  28.     }
  29.  
  30.     /** Creates a new Bitmap instance from a java.awt.image.ImageProducer.
  31.       */
  32.     public static Bitmap bitmapForAWTImageProducer(
  33.         java.awt.image.ImageProducer producer) {
  34.         return new Bitmap(
  35.                         Application.application().applet.createImage(
  36.                                                             producer));
  37.     }
  38.  
  39.     /** Returns a java.awt.Image instance from a Bitmap.
  40.       */
  41.     public static java.awt.Image awtImageForBitmap(Bitmap bitmap) {
  42.         return bitmap.awtImage;
  43.     }
  44.  
  45.     /** Returns a java.awt.image.ImageProducer instance from a Bitmap.
  46.       */
  47.     public static java.awt.image.ImageProducer awtImageProducerForBitmap(
  48.                                                             Bitmap bitmap) {
  49.         return bitmap.awtImage.getSource();
  50.     }
  51.  
  52.     /** Creates a new Sound instance from a java.applet.AudioClip.
  53.       */
  54.     public static Sound soundForAWTAudioClip(java.applet.AudioClip clip) {
  55.         Sound sound;
  56.  
  57.         sound = new Sound();
  58.         sound.awtSound = clip;
  59.  
  60.         return sound;
  61.     }
  62.  
  63.     /** Returns a java.applet.AudioClip instance from a Sound.
  64.       */
  65.     public static java.applet.AudioClip awtAudioClipForSound(Sound sound) {
  66.         return sound.awtSound;
  67.     }
  68.  
  69.     /** Creates a new Font instance from a java.awt.Font.
  70.       */
  71.     public static Font fontForAWTFont(java.awt.Font awtFont) {
  72.         Font font;
  73.  
  74.         font = new Font();
  75.         font._awtFont = awtFont;
  76.         font._name = awtFont.getName();
  77.         font._type = Font.AWT;
  78.  
  79.         return font;
  80.     }
  81.  
  82.     /** Returns a java.awt.Font instance from a Font.
  83.       */
  84.     public static java.awt.Font awtFontForFont(Font font) {
  85.         return font._awtFont;
  86.     }
  87.  
  88.     /** Creates a new Color instance from a java.awt.Color.
  89.       *
  90.       */
  91.     public static Color colorForAWTColor(java.awt.Color awtColor) {
  92.         return new Color(awtColor);
  93.     }
  94.  
  95.     /** Returns a java.awt.Color instance from a Color.
  96.       *
  97.       */
  98.     public static java.awt.Color awtColorForColor(Color color) {
  99.         return color._color;
  100.     }
  101.  
  102.     /** Creates a new FontMetrics instance from a java.awt.FontMetrics.
  103.       */
  104.     public static FontMetrics fontMetricsForAWTFontMetrics(java.awt.FontMetrics
  105.                                                             awtFontMetrics) {
  106.         return new FontMetrics(awtFontMetrics);
  107.     }
  108.  
  109.     /** Returns a java.awt.FontMetrics from a FontMetrics.
  110.       */
  111.     public static java.awt.FontMetrics awtFontMetricsForFontMetrics(FontMetrics
  112.                                                             fontMetrics) {
  113.         return fontMetrics._awtMetrics;
  114.     }
  115.  
  116.     /** Returns a java.awt.MenuBar from a Menu. Returns <b>null</b> if the
  117.       * Menu is not a top-level Menu.
  118.       */
  119.     public static java.awt.MenuBar awtMenuBarForMenu(Menu menu) {
  120.         if (menu.isTopLevel()) {
  121.             return menu.awtMenuBar();
  122.         }
  123.         return null;
  124.     }
  125.  
  126.     /** Returns a java.awt.Menu from a Menu. Returns <b>null</b> if the Menu
  127.       * is a top-level Menu.
  128.       */
  129.     public static java.awt.Menu awtMenuForMenu(Menu menu) {
  130.         if (!menu.isTopLevel()) {
  131.             return menu.awtMenu();
  132.         }
  133.         return null;
  134.     }
  135.  
  136.     /** Returns a java.awt.MenuItem from a MenuItem.
  137.       */
  138.     public static java.awt.MenuItem awtMenuItemForMenuItem(MenuItem menuItem) {
  139.         return menuItem.foundationMenuItem();
  140.     }
  141.  
  142.     /** Creates a new Graphics instance from a java.awt.Graphics.
  143.       *
  144.       */
  145.     public static Graphics graphicsForAWTGraphics(java.awt.Graphics g) {
  146.         java.awt.Rectangle r = g.getClipRect();
  147.         Rect clipRect;
  148.  
  149.         if (r != null) {
  150.             clipRect = new Rect(r.x, r.y, r.width, r.height);
  151.         } else {
  152.             clipRect = new Rect(0, 0, Integer.MAX_VALUE, Integer.MAX_VALUE);
  153.         }
  154.         return new Graphics(clipRect, g.create());
  155.     }
  156.  
  157.     /** Returns a java.awt.Graphics instance from a Graphics.
  158.       */
  159.     public static java.awt.Graphics awtGraphicsForGraphics(Graphics g) {
  160.         return g.awtGraphics();
  161.     }
  162.  
  163.     /** Returns the java.awt.Canvas underlying a RootView.
  164.       */
  165.     public static java.awt.Panel awtPanelForRootView(
  166.         RootView rootView) {
  167.         return rootView.panel();
  168.     }
  169.  
  170.     /** Returns the java.awt.Window underlying an ExternalWindow.
  171.       * This method returns <b>null</b> if the ExternalWindow <b>window</b>
  172.       * is not visible.
  173.       */
  174.     public static java.awt.Window awtWindowForExternalWindow(ExternalWindow
  175.                                                                     window) {
  176.         return window.awtWindow;
  177.     }
  178.  
  179.     /** Returns the java.applet.Applet that started this application.
  180.       */
  181.     public static java.applet.Applet awtApplet() {
  182.         Application app;
  183.  
  184.         app = Application.application();
  185.         if (app == null)
  186.             return null;
  187.  
  188.         return app.applet;
  189.     }
  190.  
  191.     /** Returns the java.awt.FileDialog used by the supplied FileChooser.
  192.       */
  193.     public static java.awt.FileDialog awtFileDialogForFileChooser(FileChooser
  194.                                                                 fileChooser) {
  195.         return fileChooser.awtDialog;
  196.     }
  197.  
  198.     /** Returns the application's Toolkit. */
  199.     public static java.awt.Toolkit awtToolkit() {
  200.         return java.awt.Toolkit.getDefaultToolkit();
  201.     }
  202.  
  203.     /** Returns the AWT Frame that contains the RootView
  204.       *
  205.       */
  206.     public static java.awt.Frame awtFrameForRootView(RootView rootView) {
  207.         return rootView.panel().frame();
  208.     }
  209. }
  210.