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