PageRenderTime 51ms CodeModel.GetById 34ms app.highlight 15ms RepoModel.GetById 0ms app.codeStats 0ms

/jEdit/tags/jedit-4-5-pre1/org/gjt/sp/jedit/gui/FloatingWindowContainer.java

#
Java | 218 lines | 149 code | 25 blank | 44 comment | 11 complexity | 3add8759c03832563c357c168840686b MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  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 java.awt.BorderLayout;
 27import java.awt.Container;
 28import java.awt.Dimension;
 29import java.awt.event.KeyListener;
 30import java.awt.event.MouseAdapter;
 31import java.awt.event.MouseEvent;
 32import java.beans.PropertyChangeEvent;
 33import java.beans.PropertyChangeListener;
 34
 35import javax.swing.Box;
 36import javax.swing.BoxLayout;
 37import javax.swing.JButton;
 38import javax.swing.JFrame;
 39import javax.swing.JPopupMenu;
 40import javax.swing.JSeparator;
 41import javax.swing.SwingUtilities;
 42
 43import org.gjt.sp.jedit.GUIUtilities;
 44import org.gjt.sp.jedit.jEdit;
 45//}}}
 46
 47/**
 48 * A container for dockable windows. This class should never be used
 49 * directly.
 50 * @version $Id: FloatingWindowContainer.java 13259 2008-08-10 20:54:46Z shlomy $
 51 * @since jEdit 4.0pre1
 52 */
 53public class FloatingWindowContainer extends JFrame implements DockableWindowContainer,
 54	PropertyChangeListener
 55{
 56	String dockableName = null;
 57	//{{{ FloatingWindowContainer constructor
 58	public FloatingWindowContainer(DockableWindowManagerImpl dockableWindowManager,
 59		boolean clone)
 60	{
 61		this.dockableWindowManager = dockableWindowManager;
 62
 63		dockableWindowManager.addPropertyChangeListener(this);
 64		this.clone = clone;
 65		setIconImage(GUIUtilities.getPluginIcon());
 66		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
 67
 68		Box caption = new Box(BoxLayout.X_AXIS);
 69		caption.add(menu = new RolloverButton(GUIUtilities
 70			.loadIcon(jEdit.getProperty("dropdown-arrow.icon"))));
 71		menu.addMouseListener(new MouseHandler());
 72		menu.setToolTipText(jEdit.getProperty("docking.menu.label"));
 73		Box separatorBox = new Box(BoxLayout.Y_AXIS);
 74		separatorBox.add(Box.createVerticalStrut(3));
 75		separatorBox.add(new JSeparator(JSeparator.HORIZONTAL));
 76		separatorBox.add(Box.createVerticalStrut(3));
 77		caption.add(separatorBox);
 78		getContentPane().add(BorderLayout.NORTH,caption);
 79	
 80		
 81	} //}}}
 82
 83	//{{{ register() method
 84	public void register(DockableWindowManagerImpl.Entry entry)
 85	{
 86		this.entry = entry;
 87		dockableName = entry.factory.name;
 88		
 89		setTitle(entry.shortTitle());
 90
 91		getContentPane().add(BorderLayout.CENTER,entry.win);
 92
 93		pack();
 94		Container parent = dockableWindowManager.getView();
 95		GUIUtilities.loadGeometry(this, parent, dockableName);
 96		GUIUtilities.addSizeSaver(this, parent, dockableName);
 97		KeyListener listener = dockableWindowManager.closeListener(dockableName);
 98		addKeyListener(listener);
 99		getContentPane().addKeyListener(listener);
100		menu.addKeyListener(listener);
101		entry.win.addKeyListener(listener);
102		setVisible(true);
103		if (! entry.win.isVisible())
104			entry.win.setVisible(true);
105	} //}}}
106
107	//{{{ remove() method
108	public void remove(DockableWindowManagerImpl.Entry entry)
109	{
110		dispose();
111	} //}}}
112
113	//{{{ unregister() method
114	public void unregister(DockableWindowManagerImpl.Entry entry)
115	{
116		this.entry = null;
117		entry.btn = null;
118		entry.container = null;
119		// Note: entry.win must not be reset, to enable the dockable
120		// instance to be moved instead of recreated if it uses the
121		// MOVABLE attribute.
122		super.dispose();
123	} //}}}
124
125	//{{{ show() method
126	public void show(final DockableWindowManagerImpl.Entry entry)
127	{
128		if(entry == null)
129			dispose();
130		else
131		{
132			setTitle(entry.longTitle());
133			toFront();
134			requestFocus();
135			SwingUtilities.invokeLater(new Runnable()
136			{
137				public void run()
138				{
139					if(entry.win instanceof DefaultFocusComponent)
140					{
141						((DefaultFocusComponent)entry.win)
142							.focusOnDefaultComponent();
143					}
144					else
145					{
146						entry.win.requestFocus();
147					}
148				}
149			});
150		}
151	} //}}}
152
153	//{{{ isVisible() method
154	public boolean isVisible(DockableWindowManagerImpl.Entry entry)
155	{
156		return true;
157	} //}}}
158
159	//{{{ dispose() method
160	@Override
161	public void dispose()
162	{
163		entry.container = null;
164		entry.win = null;
165		super.dispose();
166	} //}}}
167
168	//{{{ getDockableWindowManager() method
169	public DockableWindowManagerImpl getDockableWindowManager()
170	{
171		return dockableWindowManager;
172	} //}}}
173
174	//{{{ getMinimumSize() method
175	@Override
176	public Dimension getMinimumSize()
177	{
178		return new Dimension(0,0);
179	} //}}}
180
181	//{{{ Private members
182	private final DockableWindowManagerImpl dockableWindowManager;
183	private final boolean clone;
184	private DockableWindowManagerImpl.Entry entry;
185	private final JButton menu;
186	//}}}
187
188	//{{{ MouseHandler class
189	class MouseHandler extends MouseAdapter
190	{
191		JPopupMenu popup;
192
193		@Override
194		public void mousePressed(MouseEvent evt)
195		{
196			if(popup != null && popup.isVisible())
197				popup.setVisible(false);
198			else
199			{
200				popup = dockableWindowManager.createPopupMenu(
201					FloatingWindowContainer.this,
202					entry.factory.name,clone);
203				GUIUtilities.showPopupMenu(popup,
204					menu,menu.getX(),menu.getY() + menu.getHeight(),
205					false);
206			}
207		}
208	} //}}}
209	public void propertyChange(PropertyChangeEvent evt)
210	{
211		if (dockableName == null) return;
212		String pn = evt.getPropertyName();
213		if (pn.startsWith(dockableName) && pn.endsWith("title"))
214			setTitle(evt.getNewValue().toString());
215	}
216	
217}
218