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