001 /* 002 * $Id: JXFrame.java,v 1.6 2005/10/12 11:26:57 kleopatra Exp $ 003 * 004 * Copyright 2004 Sun Microsystems, Inc., 4150 Network Circle, 005 * Santa Clara, California 95054, U.S.A. All rights reserved. 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * You should have received a copy of the GNU Lesser General Public 018 * License along with this library; if not, write to the Free Software 019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 020 */ 021 022 package org.jdesktop.swingx; 023 024 import java.awt.Component; 025 026 import javax.swing.JFrame; 027 import javax.swing.JRootPane; 028 029 030 /** 031 * A smarter JFrame specifically used for top level frames for Applications. 032 * This frame uses a JXRootPane. 033 */ 034 public class JXFrame extends JFrame { 035 036 public JXFrame() { 037 this(null, false); 038 } 039 040 public JXFrame(String title, boolean exitOnClose) { 041 super(title); 042 if (exitOnClose) { 043 setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 044 } 045 } 046 047 public JXFrame(String title) { 048 this(title, false); 049 } 050 051 /** 052 * Overloaded to create a JXRootPane. 053 */ 054 protected JRootPane createRootPane() { 055 return new JXRootPane(); 056 } 057 058 /** 059 * Overloaded to make this public. 060 */ 061 public void setRootPane(JRootPane root) { 062 super.setRootPane(root); 063 } 064 065 /** 066 * Add a component to the Frame. 067 */ 068 public void addComponent(Component comp) { 069 JXRootPane root = getRootPaneExt(); 070 if (root != null) { 071 root.addComponent(comp); 072 } 073 // XXX should probably fire some sort of container event. 074 } 075 076 /** 077 * Removes a component from the frame. 078 */ 079 public void removeComponent(Component comp) { 080 JXRootPane root = getRootPaneExt(); 081 if (root != null) { 082 root.removeComponent(comp); 083 } 084 // XXX should probably fire some sort of container event. 085 } 086 087 /** 088 * Return the extended root pane. If this frame doesn't contain 089 * an extended root pane the root pane should be accessed with 090 * getRootPane(). 091 * 092 * @return the extended root pane or null. 093 */ 094 public JXRootPane getRootPaneExt() { 095 if (rootPane instanceof JXRootPane) { 096 return (JXRootPane)rootPane; 097 } 098 return null; 099 } 100 101 } 102