PageRenderTime 110ms CodeModel.GetById 101ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-3-pre5/org/gjt/sp/jedit/gui/FloatingWindowContainer.java

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