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