Frame.java 2.93 KB
Newer Older
Warren Levy committed
1
/* Copyright (C) 1999, 2000  Free Software Foundation
2 3 4 5 6 7 8 9 10 11 12 13 14 15

   This file is part of libjava.

This software is copyrighted work licensed under the terms of the
Libjava License.  Please consult the file "LIBJAVA_LICENSE" for
details.  */

package java.awt;
import java.awt.peer.FramePeer;

/* A very incomplete placeholder. */

public class Frame extends Window implements MenuContainer
{
16 17 18
  public static final int NORMAL = 0;
  public static final int ICONIFIED = 1;

19 20 21
  MenuBar menuBar = null;
  String title;

22 23 24 25
  private transient Image iconImage;
  private transient boolean isResizable = true;
  private transient int state = NORMAL;

26
  public Frame ()
27
  {
28 29 30 31 32 33
    super();
  }

  public Frame(GraphicsConfiguration gc)
  {
    super(gc);
34
  }
35 36 37

  public Frame (String title)
  {
38
    super();
39 40 41
    setTitle(title);
  }

42 43 44 45 46
  public Frame(String title, GraphicsConfiguration gc)
  {
    super(gc);
    setTitle(title);
  }
47

48 49 50 51 52
  public String getTitle()
  {
    return (title != null) ? title : "";
  }
    
53 54 55 56 57 58 59
  public void setTitle (String title)
  {
    this.title = title;
    if (peer != null)
      ((FramePeer)peer).setTitle(title);
  }

60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
  public Image getIconImage()
  {
    return iconImage;
  }
  
  public void setIconImage(Image image)
  {
    iconImage = image;
    if (peer != null)
      ((FramePeer) peer).setIconImage(iconImage);
  }

  protected void finalize() throws Throwable
  {
    //frames.remove(this);
    /* FIXME: This won't work. Finalize will never be called if frames
       has a reference to the object. We need weak references to
       implement this correctly. */

    super.finalize();
  }
81 82

  public synchronized void setMenuBar (MenuBar menuBar)
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
  { 
    if (this.menuBar != menuBar)
      {
	//this.menuBar.removeNotify();
	this.menuBar = menuBar;
	//this.menuBar.addNotify();
      }	

    if (peer != null)
      ((FramePeer) peer).setMenuBar(menuBar);
  }
  
  public boolean isResizable()
  {
    return isResizable;
  }

  public void setResizable(boolean resizable)
  {
    isResizable = resizable;
    if (peer != null)
      ((FramePeer) peer).setResizable(isResizable);
  }

  public int getState()
  {
    /* FIXME: State might have changed in the peer... Must check. */
    
    return state;
  }

114 115 116 117

  public synchronized void addNotify ()
  {
    if (peer == null)
118
      peer = getToolkit ().createFrame (this);
119 120
    super.addNotify();
  }
Warren Levy committed
121

122
  public boolean postEvent(Event evt) { return false; } // FIXME
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
 
  public void remove(MenuComponent m)
  {
    if (m == menuBar)
      {
	setMenuBar(null);
	return;
      }
	
    super.remove(m);
  }
  
  public void removeNotify()
  {
    //if ((peer != null) && (menuBar != null)) menuBar.removeNotify();
    super.removeNotify();
  }
    
  public static Frame[] getFrames()
  {
    //Frame[] array = new Frames[frames.size()];
    //return frames.toArray(array);
    
    // see finalize() comment
    String msg = "FIXME: can't be implemented without weak references";
    throw new UnsupportedOperationException(msg);
  }
150
}