PageRenderTime 84ms CodeModel.GetById 72ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre4/org/gjt/sp/jedit/gui/FloatingWindowContainer.java

#
Java | 167 lines | 109 code | 17 blank | 41 comment | 6 complexity | f3af73c727a1fea5495a28409842c85c MD5 | raw file
  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
 23package org.gjt.sp.jedit.gui;
 24
 25//{{{ Imports
 26import javax.swing.*;
 27import java.awt.event.*;
 28import java.awt.*;
 29import org.gjt.sp.jedit.*;
 30//}}}
 31
 32/**
 33 * A container for dockable windows. This class should never be used
 34 * directly.
 35 * @version $Id: FloatingWindowContainer.java 4692 2003-05-07 22:40:00Z spestov $
 36 * @since jEdit 4.0pre1
 37 */
 38public class FloatingWindowContainer extends JFrame implements DockableWindowContainer
 39{
 40	//{{{ FloatingWindowContainer constructor
 41	public FloatingWindowContainer(DockableWindowManager dockableWindowManager,
 42		boolean clone)
 43	{
 44		this.dockableWindowManager = dockableWindowManager;
 45		this.clone = clone;
 46		setIconImage(GUIUtilities.getPluginIcon());
 47		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
 48
 49		Box caption = new Box(BoxLayout.X_AXIS);
 50		caption.add(menu = new RolloverButton(GUIUtilities
 51			.loadIcon("ToolbarMenu.gif")));
 52		menu.addMouseListener(new MouseHandler());
 53		Box separatorBox = new Box(BoxLayout.Y_AXIS);
 54		separatorBox.add(Box.createVerticalStrut(3));
 55		separatorBox.add(new JSeparator(JSeparator.HORIZONTAL));
 56		separatorBox.add(Box.createVerticalStrut(3));
 57		caption.add(separatorBox);
 58		getContentPane().add(BorderLayout.NORTH,caption);
 59	} //}}}
 60
 61	//{{{ register() method
 62	public void register(DockableWindowManager.Entry entry)
 63	{
 64		this.entry = entry;
 65		setTitle(entry.title);
 66
 67		getContentPane().add(BorderLayout.CENTER,entry.win);
 68
 69		pack();
 70		GUIUtilities.loadGeometry(this,entry.factory.name);
 71		show();
 72	} //}}}
 73
 74	//{{{ remove() method
 75	public void remove(DockableWindowManager.Entry entry)
 76	{
 77		dispose();
 78	} //}}}
 79
 80	//{{{ unregister() method
 81	public void unregister(DockableWindowManager.Entry entry)
 82	{
 83		dispose();
 84	} //}}}
 85
 86	//{{{ show() method
 87	public void show(final DockableWindowManager.Entry entry)
 88	{
 89		if(entry == null)
 90			dispose();
 91		else
 92		{
 93			toFront();
 94			requestFocus();
 95			SwingUtilities.invokeLater(new Runnable()
 96			{
 97				public void run()
 98				{
 99					if(entry.win instanceof DefaultFocusComponent)
100					{
101						((DefaultFocusComponent)entry.win)
102							.focusOnDefaultComponent();
103					}
104					else
105					{
106						entry.win.requestDefaultFocus();
107					}
108				}
109			});
110		}
111	} //}}}
112
113	//{{{ isVisible() method
114	public boolean isVisible(DockableWindowManager.Entry entry)
115	{
116		return true;
117	} //}}}
118
119	//{{{ dispose() method
120	public void dispose()
121	{
122		GUIUtilities.saveGeometry(this,entry.factory.name);
123		entry.container = null;
124		entry.win = null;
125		super.dispose();
126	} //}}}
127
128	//{{{ getDockableWindowManager() method
129	public DockableWindowManager getDockableWindowManager()
130	{
131		return dockableWindowManager;
132	} //}}}
133
134	//{{{ getMinimumSize() method
135	public Dimension getMinimumSize()
136	{
137		return new Dimension(0,0);
138	} //}}}
139
140	//{{{ Private members
141	private DockableWindowManager dockableWindowManager;
142	private boolean clone;
143	private DockableWindowManager.Entry entry;
144	private JButton menu;
145	//}}}
146
147	//{{{ MouseHandler class
148	class MouseHandler extends MouseAdapter
149	{
150		JPopupMenu popup;
151
152		public void mousePressed(MouseEvent evt)
153		{
154			if(popup != null && popup.isVisible())
155				popup.setVisible(false);
156			else
157			{
158				popup = dockableWindowManager.createPopupMenu(
159					FloatingWindowContainer.this,
160					entry.factory.name,clone);
161				GUIUtilities.showPopupMenu(popup,
162					menu,menu.getX(),menu.getY() + menu.getHeight(),
163					false);
164			}
165		}
166	} //}}}
167}