Java Source Code: jp.ujihara.javax.swing.JFrame


   1: /* JFrame.java --
   2:    Copyright (C) 2002, 2004 Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   6: GNU Classpath is free software; you can redistribute it and/or modify
   7: it under the terms of the GNU General Public License as published by
   8: the Free Software Foundation; either version 2, or (at your option)
   9: any later version.
  10: 
  11: GNU Classpath is distributed in the hope that it will be useful, but
  12: WITHOUT ANY WARRANTY; without even the implied warranty of
  13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14: General Public License for more details.
  15: 
  16: You should have received a copy of the GNU General Public License
  17: along with GNU Classpath; see the file COPYING.  If not, write to the
  18: Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  19: 02111-1307 USA.
  20: 
  21: Linking this library statically or dynamically with other modules is
  22: making a combined work based on this library.  Thus, the terms and
  23: conditions of the GNU General Public License cover the whole
  24: combination.
  25: 
  26: As a special exception, the copyright holders of this library give you
  27: permission to link this library with independent modules to produce an
  28: executable, regardless of the license terms of these independent
  29: modules, and to copy and distribute the resulting executable under
  30: terms of your choice, provided that you also meet, for each linked
  31: independent module, the terms and conditions of the license of that
  32: module.  An independent module is a module which is not derived from
  33: or based on this library.  If you modify this library, you may extend
  34: this exception to your version of the library, but you are not
  35: obligated to do so.  If you do not wish to do so, delete this
  36: exception statement from your version. */
  37: 
  38: 
  39: package jp.ujihara.javax.swing;
  40: 
  41: import jp.ujihara.java.awt.AWTEvent;
  42: import jp.ujihara.java.awt.BorderLayout;
  43: import jp.ujihara.java.awt.Component;
  44: import jp.ujihara.java.awt.Container;
  45: import jp.ujihara.java.awt.Dimension;
  46: import jp.ujihara.java.awt.Frame;
  47: import jp.ujihara.java.awt.Graphics;
  48: import jp.ujihara.java.awt.LayoutManager;
  49: import jp.ujihara.java.awt.event.KeyEvent;
  50: import jp.ujihara.java.awt.event.WindowEvent;
  51: 
  52: import jp.ujihara.javax.accessibility.AccessibleContext;
  53: 
  54: /**
  55:  * Unlike JComponent derivatives, JFrame inherits from
  56:  * jp.ujihara.java.awt.Frame. But also lets a look-and-feel component to its work.
  57:  *
  58:  * @author Ronald Veldema (rveldema@cs.vu.nl)
  59:  */
  60: public class JFrame extends Frame
  61:   implements WindowConstants, RootPaneContainer
  62:	  {
  63:  private static final long serialVersionUID = -3362141868504252139L;
  64:  private static boolean defaultLookAndFeelDecorated;
  65:  private int close_action = HIDE_ON_CLOSE;
  66:  protected AccessibleContext accessibleContext;
  67:  protected JRootPane rootPane;
  68:  protected boolean rootPaneCheckingEnabled;
  69:
  70:  public JFrame()
  71:	    {
  72:    super("JFrame");
  73:    frameInit();
  74:  }
  75:
  76:  public JFrame(String title)
  77:	    {
  78:    super(title);
  79:    frameInit();
  80:  }
  81:
  82:  protected void frameInit()
  83:	    {
  84:    super.setLayout(new BorderLayout(1, 1));
  85:    enableEvents(AWTEvent.WINDOW_EVENT_MASK);
  86:    getRootPane(); // will do set/create
  87:  }
  88:
  89:  public Dimension getPreferredSize()
  90:	    {
  91:    return super.getPreferredSize();
  92:  }
  93:
  94:  public JMenuBar getJMenuBar()
  95:	    {
  96:    return getRootPane().getJMenuBar();
  97:  }
  98:
  99:  public void setJMenuBar(JMenuBar menubar)
 100:	    {
 101:    getRootPane().setJMenuBar(menubar);
 102:  }
 103:
 104:  public void setLayout(LayoutManager manager)
 105:	    {
 106:    super.setLayout(manager);
 107:  }
 108:
 109:  public void setLayeredPane(JLayeredPane layeredPane)
 110:	    {
 111:    getRootPane().setLayeredPane(layeredPane);
 112:  }
 113:
 114:  public JLayeredPane getLayeredPane()
 115:	    {
 116:    return getRootPane().getLayeredPane();
 117:  }
 118:
 119:  public JRootPane getRootPane()
 120:	    {
 121:    if (rootPane == null)
 122:      setRootPane(createRootPane());
 123:    return rootPane;
 124:  }
 125:
 126:  public void setRootPane(JRootPane root)
 127:	    {
 128:    if (rootPane != null)
 129:      remove(rootPane);
 130:
 131:    rootPane = root;
 132:    add(rootPane, BorderLayout.CENTER);
 133:  }
 134:
 135:  public JRootPane createRootPane()
 136:	    {
 137:    return new JRootPane();
 138:  }
 139:
 140:  public Container getContentPane()
 141:	    {
 142:    return getRootPane().getContentPane();
 143:  }
 144:
 145:  public void setContentPane(Container contentPane)
 146:	    {
 147:    getRootPane().setContentPane(contentPane);
 148:  }
 149:
 150:  public Component getGlassPane()
 151:	    {
 152:    return getRootPane().getGlassPane();
 153:  }
 154:
 155:  public void setGlassPane(Component glassPane)
 156:	    {
 157:    getRootPane().setGlassPane(glassPane);
 158:  }
 159:
 160:  protected void addImpl(Component comp, Object constraints, int index)
 161:	    {
 162:    super.addImpl(comp, constraints, index);
 163:  }
 164:
 165:  public void remove(Component comp)
 166:	    {
 167:    getContentPane().remove(comp);
 168:  }
 169:
 170:  protected boolean isRootPaneCheckingEnabled()
 171:	    {
 172:    return rootPaneCheckingEnabled;
 173:  }
 174:
 175:  protected void setRootPaneCheckingEnabled(boolean enabled)
 176:	    {
 177:    rootPaneCheckingEnabled = enabled;
 178:  }
 179:
 180:  public void update(Graphics g)
 181:	    {
 182:    paint(g);
 183:  }
 184:
 185:  protected void processKeyEvent(KeyEvent e)
 186:	    {
 187:    super.processKeyEvent(e);
 188:  }
 189:
 190:  public static void setDefaultLookAndFeelDecorated(boolean decorated)
 191:	    {
 192:    defaultLookAndFeelDecorated = decorated;
 193:  }
 194:
 195:  public static boolean isDefaultLookAndFeelDecorated()
 196:	    {
 197:    return defaultLookAndFeelDecorated;
 198:  }
 199:
 200:  public AccessibleContext getAccessibleContext()
 201:	    {
 202:    return accessibleContext;
 203:  }
 204:
 205:  public int getDefaultCloseOperation()
 206:	    {
 207:    return close_action;
 208:  }
 209:
 210:  protected String paramString()
 211:	    {
 212:    return "JFrame";
 213:  }
 214:
 215:  protected void processWindowEvent(WindowEvent e)
 216:	    {
 217:    super.processWindowEvent(e);
 218:    switch (e.getID())
 219:	        {
 220:      case WindowEvent.WINDOW_CLOSING:
 221:	          {
 222:      switch (close_action)
 223:	          {
 224:        case EXIT_ON_CLOSE:
 225:	            {
 226:        System.exit(0);
 227:        break;
 228:          }
 229:        case DISPOSE_ON_CLOSE:
 230:	            {
 231:        dispose();
 232:        break;
 233:          }
 234:        case HIDE_ON_CLOSE:
 235:	            {
 236:        setVisible(false);
 237:        break;
 238:          }
 239:        case DO_NOTHING_ON_CLOSE:
 240:          break;
 241:        }
 242:      break;
 243:        }
 244:      case WindowEvent.WINDOW_CLOSED:
 245:      case WindowEvent.WINDOW_OPENED:
 246:      case WindowEvent.WINDOW_ICONIFIED:
 247:      case WindowEvent.WINDOW_DEICONIFIED:
 248:      case WindowEvent.WINDOW_ACTIVATED:
 249:      case WindowEvent.WINDOW_DEACTIVATED:
 250:    break;
 251:      }
 252:  }
 253:
 254:  /**
 255:   * Defines what happens when this frame is closed. Can be one off
 256:   * <code>EXIT_ON_CLOSE</code>,
 257:   * <code>DISPOSE_ON_CLOSE</code>,
 258:   * <code>HIDE_ON_CLOSE</code> or
 259:   * <code>DO_NOTHING_ON_CLOSE</code>.
 260:   * The default is <code>HIDE_ON_CLOSE</code>.
 261:   * When <code>EXIT_ON_CLOSE</code> is specified this method calls
 262:   * <code>SecurityManager.checkExit(0)</code> which might throw a
 263:   * <code>SecurityException</code>. When the specified operation is
 264:   * not one of the above a <code>IllegalArgumentException</code> is
 265:   * thrown.
 266:   */
 267:  public void setDefaultCloseOperation(int operation)
 268:	    {
 269:    jp.ujihara.java.lang.SecurityManager sm = jp.ujihara.java.lang.System.getSecurityManager();
 270:    if (sm != null && operation == EXIT_ON_CLOSE)
 271:      sm.checkExit(0);
 272:
 273:    if (operation != EXIT_ON_CLOSE && operation != DISPOSE_ON_CLOSE
 274:        && operation != HIDE_ON_CLOSE && operation != DO_NOTHING_ON_CLOSE)
 275:      throw new jp.ujihara.java.lang.ClasspathIllegalArgumentException("operation = " + operation);
 276:
 277:    close_action = operation;
 278:  }
 279:}