KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > gjt > sp > jedit > gui > FloatingWindowContainer


1 /*
2  * FloatingWindowContainer.java - holds dockable windows
3  * :tabSize=8:indentSize=8:noTabs=false:
4  * :folding=explicit:collapseFolds=1:
5  *
6  * Copyright (C) 2000, 2001, 2002 Slava Pestov
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21  */

22
23 package org.gjt.sp.jedit.gui;
24
25 //{{{ Imports
26
import java.awt.BorderLayout JavaDoc;
27 import java.awt.Component JavaDoc;
28 import java.awt.Container JavaDoc;
29 import java.awt.Window JavaDoc;
30 import java.awt.Dimension JavaDoc;
31 import java.awt.event.KeyListener JavaDoc;
32 import java.awt.event.MouseAdapter JavaDoc;
33 import java.awt.event.MouseEvent JavaDoc;
34 import java.beans.PropertyChangeEvent JavaDoc;
35 import java.beans.PropertyChangeListener JavaDoc;
36
37 import javax.swing.Box JavaDoc;
38 import javax.swing.BoxLayout JavaDoc;
39 import javax.swing.JButton JavaDoc;
40 import javax.swing.JFrame JavaDoc;
41 import javax.swing.JPopupMenu JavaDoc;
42 import javax.swing.JSeparator JavaDoc;
43 import javax.swing.SwingUtilities JavaDoc;
44
45 import org.gjt.sp.jedit.GUIUtilities;
46 import org.gjt.sp.jedit.jEdit;
47 //}}}
48

49 /**
50  * A container for dockable windows. This class should never be used
51  * directly.
52  * @version $Id: FloatingWindowContainer.java 6884 2006-09-06 02:38:55Z ezust $
53  * @since jEdit 4.0pre1
54  */

55 public class FloatingWindowContainer extends JFrame JavaDoc implements DockableWindowContainer,
56     PropertyChangeListener JavaDoc
57 {
58     String JavaDoc dockableName = null;
59     //{{{ FloatingWindowContainer constructor
60
public FloatingWindowContainer(DockableWindowManager dockableWindowManager,
61         boolean clone)
62     {
63         this.dockableWindowManager = dockableWindowManager;
64
65         dockableWindowManager.addPropertyChangeListener(this);
66         this.clone = clone;
67         setIconImage(GUIUtilities.getPluginIcon());
68         setDefaultCloseOperation(DISPOSE_ON_CLOSE);
69
70         Box JavaDoc caption = new Box JavaDoc(BoxLayout.X_AXIS);
71         caption.add(menu = new RolloverButton(GUIUtilities
72             .loadIcon("ToolbarMenu.gif")));
73         menu.addMouseListener(new MouseHandler());
74         menu.setToolTipText(jEdit.getProperty("docking.menu.label"));
75         Box JavaDoc separatorBox = new Box JavaDoc(BoxLayout.Y_AXIS);
76         separatorBox.add(Box.createVerticalStrut(3));
77         separatorBox.add(new JSeparator JavaDoc(JSeparator.HORIZONTAL));
78         separatorBox.add(Box.createVerticalStrut(3));
79         caption.add(separatorBox);
80         getContentPane().add(BorderLayout.NORTH,caption);
81     
82         
83     } //}}}
84

85     //{{{ register() method
86
public void register(DockableWindowManager.Entry entry)
87     {
88         this.entry = entry;
89         dockableName = entry.factory.name;
90         
91         setTitle(entry.shortTitle());
92
93         getContentPane().add(BorderLayout.CENTER,entry.win);
94
95         pack();
96         Container JavaDoc parent = dockableWindowManager.getView();
97         GUIUtilities.loadGeometry(this, parent, dockableName);
98         GUIUtilities.addSizeSaver(this, parent, dockableName);
99         KeyListener JavaDoc listener = dockableWindowManager.closeListener(dockableName);
100         addKeyListener(listener);
101         getContentPane().addKeyListener(listener);
102         menu.addKeyListener(listener);
103         entry.win.addKeyListener(listener);
104         setVisible(true);
105     } //}}}
106

107     //{{{ remove() method
108
public void remove(DockableWindowManager.Entry entry)
109     {
110         entry.container = null;
111         dispose();
112     } //}}}
113

114     //{{{ unregister() method
115
public void unregister(DockableWindowManager.Entry entry)
116     {
117         dispose();
118     } //}}}
119

120     //{{{ show() method
121
public void show(final DockableWindowManager.Entry entry)
122     {
123         if(entry == null)
124             dispose();
125         else
126         {
127             setTitle(entry.longTitle());
128             toFront();
129             requestFocus();
130             SwingUtilities.invokeLater(new Runnable JavaDoc()
131             {
132                 public void run()
133                 {
134                     if(entry.win instanceof DefaultFocusComponent)
135                     {
136                         ((DefaultFocusComponent)entry.win)
137                             .focusOnDefaultComponent();
138                     }
139                     else
140                     {
141                         entry.win.requestFocus();
142                     }
143                 }
144             });
145         }
146     } //}}}
147

148     //{{{ isVisible() method
149
public boolean isVisible(DockableWindowManager.Entry entry)
150     {
151         return true;
152     } //}}}
153

154     //{{{ dispose() method
155
public void dispose()
156     {
157         entry.container = null;
158         entry.win = null;
159         super.dispose();
160     } //}}}
161

162     //{{{ getDockableWindowManager() method
163
public DockableWindowManager getDockableWindowManager()
164     {
165         return dockableWindowManager;
166     } //}}}
167

168     //{{{ getMinimumSize() method
169
public Dimension JavaDoc getMinimumSize()
170     {
171         return new Dimension JavaDoc(0,0);
172     } //}}}
173

174     //{{{ Private members
175
private DockableWindowManager dockableWindowManager;
176     private boolean clone;
177     private DockableWindowManager.Entry entry;
178     private JButton JavaDoc menu;
179     //}}}
180

181     //{{{ MouseHandler class
182
class MouseHandler extends MouseAdapter JavaDoc
183     {
184         JPopupMenu JavaDoc popup;
185
186         public void mousePressed(MouseEvent JavaDoc evt)
187         {
188             if(popup != null && popup.isVisible())
189                 popup.setVisible(false);
190             else
191             {
192                 popup = dockableWindowManager.createPopupMenu(
193                     FloatingWindowContainer.this,
194                     entry.factory.name,clone);
195                 GUIUtilities.showPopupMenu(popup,
196                     menu,menu.getX(),menu.getY() + menu.getHeight(),
197                     false);
198             }
199         }
200     } //}}}
201
public void propertyChange(PropertyChangeEvent JavaDoc evt)
202     {
203         if (dockableName == null) return;
204         String JavaDoc pn = evt.getPropertyName();
205         if (pn.startsWith(dockableName) && pn.endsWith("title"))
206             setTitle(evt.getNewValue().toString());
207     }
208     
209 }
210
211
Popular Tags