001/* ----------------------------------------------------------------------------
002   The Kiwi Toolkit - A Java Class Library
003   Copyright (C) 1998-2004 Mark A. Lindner
004
005   This library is free software; you can redistribute it and/or
006   modify it under the terms of the GNU General Public License as
007   published by the Free Software Foundation; either version 2 of the
008   License, or (at your option) any later version.
009
010   This library is distributed in the hope that it will be useful,
011   but WITHOUT ANY WARRANTY; without even the implied warranty of
012   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
013   General Public License for more details.
014
015   You should have received a copy of the GNU General Public License
016   along with this library; if not, write to the Free Software
017   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
018   02111-1307, USA.
019 
020   The author may be contacted at: mark_a_lindner@yahoo.com
021   ----------------------------------------------------------------------------
022   $Log: KInternalFrame.java,v $
023   Revision 1.7  2004/05/12 19:07:29  markl
024   comment block updates
025
026   Revision 1.6  2003/01/19 09:50:53  markl
027   Javadoc & comment header updates.
028
029   Revision 1.5  2001/03/12 09:27:56  markl
030   Source code and Javadoc cleanup.
031
032   Revision 1.4  1999/07/19 03:59:34  markl
033   Fixed listener problem, renamed dispose() to destroy().
034
035   Revision 1.3  1999/07/12 08:50:52  markl
036   Listen for texture change events.
037
038   Revision 1.2  1999/07/06 09:17:22  markl
039   Added cursor method.
040
041   Revision 1.1  1999/05/10 08:58:32  markl
042   Initial revision
043   ----------------------------------------------------------------------------
044*/
045
046package kiwi.ui;
047
048import java.awt.*;
049import java.awt.event.*;
050import java.beans.*;
051import javax.swing.*;
052import javax.swing.event.*;
053
054import kiwi.util.*;
055
056/** <code>KInternalFrame</code> is a trivial extension of
057 * <code>JInternalFrame</code> that provides support for tiling the background
058 * of the frame with an image.
059 * <p>
060 * The method <code>getMainContainer()</code> will return the frame's
061 * <code>KPanel</code>. Add child components to the frame by adding
062 * them to this <code>KPanel</code>.
063 *
064 * <p><center>
065 * <img src="snapshot/KInternalFrame.gif"><br>
066 * <i>An example KInternalFrame.</i>
067 * </center>
068 *
069 * @see kiwi.ui.KPanel
070 *
071 * @author Mark Lindner
072 */
073
074public class KInternalFrame extends JInternalFrame
075  {
076  private KPanel _main;
077  private _PropertyChangeListener propListener;
078
079  /** Construct a new <code>KInternalFrame</code> that is non-resizable,
080   * non-closable, non-maximizable, non-iconifiable, and with no title. */
081
082  public KInternalFrame()
083    {
084    this("", false, false, false, false);
085    }
086
087  /** Construct a new <code>KInternalFrame</code> that is non-resizable,
088   * non-closable, non-maximizable, non-iconifiable, and with the specified
089   * title.
090   *
091   * @param title The title for the frame.
092   */
093
094  public KInternalFrame(String title)
095    {
096    this(title, false, false, false, false);
097    }
098
099  /** Construct a new <code>KInternalFrame</code> that is non-closable,
100   * non-maximizable, non-iconifiable, and with the specified resizability and
101   * title.
102   *
103   * @param title The title for the frame.
104   * @param resizable A flag specifying whether the frame will be resizable.
105   */
106  
107  public KInternalFrame(String title, boolean resizable)
108    {
109    this(title, resizable, false, false, false);
110    }
111
112  /** Construct a new <code>KInternalFrame</code> that is non-maximizable,
113   * non-iconifiable, and with the specified resizability, closability, and
114   * title.
115   *
116   * @param title The title for the frame.
117   * @param resizable A flag specifying whether the frame will be resizable.
118   * @param closable A flag specifying whether the frame will be closable.
119   */
120  
121  public KInternalFrame(String title, boolean resizable, boolean closable)
122    {
123    this(title, resizable, closable, false, false);
124    }
125
126  /** Construct a new <code>KInternalFrame</code> that is non-iconifiable, and
127   * with the specified resizability, closability, maximizability, and
128   * title.
129   *
130   * @param title The title for the frame.
131   * @param resizable A flag specifying whether the frame will be resizable.
132   * @param closable A flag specifying whether the frame will be closable.
133   * @param maximizable A flag specifying whether the frame will be
134   * maximizable.
135   */
136  
137  public KInternalFrame(String title, boolean resizable, boolean closable,
138                        boolean maximizable)
139    {
140    this(title, resizable, closable, maximizable, false);
141    }
142
143  /** Construct a new <code>KInternalFrame</code> with the specified
144   * resizability, closability, maximizability, iconafiability, and title.
145   *
146   * @param title The title for the frame.
147   * @param resizable A flag specifying whether the frame will be resizable.
148   * @param closable A flag specifying whether the frame will be closable.
149   * @param maximizable A flag specifying whether the frame will be
150   * maximizable.
151   * @param iconifiable A flag specifying whether the frame will be
152   * iconifiable.
153   */
154  
155  public KInternalFrame(String title, boolean resizable, boolean closable,
156                        boolean maximizable, boolean iconifiable)
157    {
158    super(title, resizable, closable, maximizable, iconifiable);
159
160    addInternalFrameListener(new _WindowListener());
161    
162    ResourceManager rm = KiwiUtils.getResourceManager();
163    getContentPane().setLayout(new GridLayout(1, 0));
164    _main = new KPanel(UIChangeManager.getInstance()
165                              .getDefaultTexture());
166    _main.setOpaque(true);
167    getContentPane().add(_main);
168    setFrameIcon(rm.getIcon("kiwi-icon.gif"));
169
170    UIChangeManager.getInstance().registerComponent(getRootPane());
171    propListener = new _PropertyChangeListener();
172    UIChangeManager.getInstance().addPropertyChangeListener(propListener);
173    }
174
175  /** Get a reference to the main container (in this case, the
176    * <code>KPanel</code> that is the child of the frame's content pane).
177    */
178
179  public KPanel getMainContainer()
180    {
181    return(_main);
182    }
183
184  /** Set the background texture.
185    *
186    * @param image The image to use as the background texture for the frame.
187    */
188
189  public void setTexture(Image image)
190    {
191    _main.setTexture(image);
192    invalidate();
193    repaint();
194    }
195
196  /** Set the background color.
197   *
198   * @param color The new background color.
199   */
200  
201  public void setColor(Color color)
202    {
203    _main.setBackground(color);
204    }
205
206  /** Called in response to a frame close event to determine if this frame
207   * may be closed.
208   *
209   * @return <code>true</code> if the frame is allowed to close, and
210   * <code>false</code> otherwise. The default implementation returns
211   * <code>true</code>.
212   */
213  
214  protected boolean canClose()
215    {
216    return(true);
217    }
218
219  /** Show or hide the frame.
220   *
221   * @param flag A flag specifying whether the frame should be shown or
222   * hidden. If <code>true</code>, the <code>startFocus()</code> method is
223   * called to allow the subclasser to request focus for a given child
224   * component.
225   *
226   * @see #startFocus
227   */
228  
229  public void setVisible(boolean flag)
230    {
231    if(flag)
232      startFocus();
233
234    super.setVisible(flag);
235    }
236  
237  /** This method is called when the frame is made visible; it should
238   * transfer focus to the appropriate child component. The default
239   * implementation does nothing.
240   */
241  
242  protected void startFocus()
243    {
244    }
245  
246  /** Turn the busy cursor on or off for this window.
247   *
248   * @param flag If <code>true</code>, the wait cursor will be set for this
249   * window, otherwise the default cursor will be set.
250   */
251  
252  public void setBusyCursor(boolean flag)
253    {
254    setCursor(Cursor.getPredefinedCursor(flag ? Cursor.WAIT_CURSOR
255                                         : Cursor.DEFAULT_CURSOR));
256    }
257  
258  /** Destroy this frame. Call this method when the frame is no longer needed.
259   * The frame will detach its listeners from the
260   * <code>UIChanageManager</code>.
261   */
262
263  public void destroy()
264    {
265    UIChangeManager.getInstance().unregisterComponent(getRootPane());
266    UIChangeManager.getInstance().removePropertyChangeListener(propListener);
267    }
268
269  /* WindowListener */
270  
271  private class _WindowListener extends InternalFrameAdapter
272    {
273    public void internalFrameClosing(InternalFrameEvent evt)
274      {
275      if(canClose())
276        {
277        setVisible(false);
278        dispose();
279        }
280      }
281    }
282
283  /* PropertyChangeListener */
284
285  private class _PropertyChangeListener implements PropertyChangeListener
286    {
287    public void propertyChange(PropertyChangeEvent evt)
288      {
289      if(evt.getPropertyName().equals(UIChangeManager.TEXTURE_PROPERTY))
290        setTexture((Image)evt.getNewValue());
291      }
292    }
293
294  }
295
296/* end of source file */