1 /*****************************************************/
\r
2 /* This java file is a part of the */
\r
4 /* - Plouf's Java IRC Client - */
\r
6 /* Copyright (C) 2002 - 2005 Philippe Detournay */
\r
8 /* All contacts : theplouf@yahoo.com */
\r
10 /* PJIRC is free software; you can redistribute */
\r
11 /* it and/or modify it under the terms of the GNU */
\r
12 /* General Public License as published by the */
\r
13 /* Free Software Foundation; version 2 or later of */
\r
16 /* PJIRC is distributed in the hope that it will */
\r
17 /* be useful, but WITHOUT ANY WARRANTY; without */
\r
18 /* even the implied warranty of MERCHANTABILITY or */
\r
19 /* FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
\r
20 /* General Public License for more details. */
\r
22 /* You should have received a copy of the GNU */
\r
23 /* General Public License along with PJIRC; if */
\r
24 /* not, write to the Free Software Foundation, */
\r
25 /* Inc., 59 Temple Place, Suite 330, Boston, */
\r
26 /* MA 02111-1307 USA */
\r
28 /*****************************************************/
\r
30 package irc.gui.common;
\r
32 import irc.EventDispatcher;
\r
33 import irc.ListenerGroup;
\r
35 import java.awt.BorderLayout;
\r
36 import java.awt.Color;
\r
37 import java.awt.Component;
\r
38 import java.awt.Frame;
\r
39 import java.awt.Panel;
\r
40 import java.awt.event.WindowEvent;
\r
41 import java.awt.event.WindowListener;
\r
44 * A panel that can be docked.
\r
46 public class DockablePanel extends Panel implements WindowListener, Runnable {
\r
47 private Component _comp;
\r
48 private boolean _docked;
\r
49 private Frame _frame;
\r
50 private int _behaviour;
\r
51 private ListenerGroup _listeners;
\r
54 * Closing behaviour: the panel will be docked upon undocked window closure.
\r
56 public static final int DOCK_ON_CLOSE = 0;
\r
59 * Closing behaviour: nothing will be done upon undocked window closure.
\r
61 public static final int DO_NOTHING_ON_CLOSE = 1;
\r
64 * Create a new Dockable Panel using the given component inside, and the given
\r
68 * the unique component of this panel.
\r
70 * the background color when the component is undocked.
\r
72 public DockablePanel(Component c, Color col) {
\r
74 setLayout(new BorderLayout());
\r
77 add(_comp, BorderLayout.CENTER);
\r
80 _frame = new Frame();
\r
81 _frame.setLayout(new BorderLayout());
\r
82 _frame.addWindowListener(this);
\r
84 _behaviour = DOCK_ON_CLOSE;
\r
85 _listeners = new ListenerGroup();
\r
89 * Add a new dockable panel listener.
\r
92 * the listener to add.
\r
94 public void addDockablePanelListener(DockablePanelListener lis) {
\r
95 _listeners.addListener(lis);
\r
99 * Removes a dockable panel listener.
\r
102 * the listener to remove.
\r
104 public void removeDockablePanelListener(DockablePanelListener lis) {
\r
105 _listeners.removeListener(lis);
\r
109 * Set the undocked window closing behaviour.
\r
112 * the new behaviour. By default, the behaviour is DOCK_ON_CLOSE.
\r
114 public void setClosingBehaviour(int behaviour) {
\r
115 _behaviour = behaviour;
\r
119 * Get the undocked window closing behaviour.
\r
121 * @return the window closing behaviour.
\r
123 public int getClosingBehaviour() {
\r
128 * Get the component.
\r
130 * @return the component.
\r
132 public Component getComponent() {
\r
137 * Undock the panel.
\r
139 * @param windowTitle
\r
140 * the undocked window title.
\r
142 public void undock(String windowTitle) {
\r
148 _comp.setVisible(true);
\r
151 _frame.add(_comp, BorderLayout.CENTER);
\r
153 _frame.setTitle(windowTitle);
\r
160 public void dock() {
\r
166 _comp.setVisible(false);
\r
168 _frame.remove(_comp);
\r
170 add(_comp, BorderLayout.CENTER);
\r
171 _comp.setVisible(isVisible());
\r
176 * Check the dock state.
\r
178 * @return if docked, false otherwise.
\r
180 public boolean isDocked() {
\r
185 * If the source is undocked, this method will bring the undocked window to
\r
186 * the front of the screen.
\r
188 public void bring() {
\r
193 public void run() {
\r
194 if (_frame != null)
\r
200 * Release this object.
\r
202 public void release() {
\r
203 if (_frame == null)
\r
206 _frame.removeAll();
\r
208 _frame.removeWindowListener(this);
\r
209 // EventDispatcher.dispatchEventAsync(this,"disposeFrame",new Object[0]);
\r
210 Thread t = new Thread(this, "Frame disposal thread");
\r
216 public void setVisible(boolean b) {
\r
220 _comp.setVisible(b);
\r
221 super.setVisible(b);
\r
225 public void windowActivated(WindowEvent e) {
\r
230 public void windowClosed(WindowEvent e) {
\r
231 _listeners.sendEventAsync("DockablePanelWindowClosed", this);
\r
235 public void windowClosing(WindowEvent e) {
\r
236 _listeners.sendEventAsync("DockablePanelWindowClosing", this);
\r
237 if (_behaviour == DOCK_ON_CLOSE)
\r
238 EventDispatcher.dispatchEventAsync(this, "dock", new Object[0]);
\r
242 public void windowDeactivated(WindowEvent e) {
\r
247 public void windowDeiconified(WindowEvent e) {
\r
252 public void windowIconified(WindowEvent e) {
\r
257 public void windowOpened(WindowEvent e) {
\r