001: /*
002: * FloatingWindowContainer.java - holds dockable windows
003: * :tabSize=8:indentSize=8:noTabs=false:
004: * :folding=explicit:collapseFolds=1:
005: *
006: * Copyright (C) 2000, 2001, 2002 Slava Pestov
007: *
008: * This program is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public License
010: * as published by the Free Software Foundation; either version 2
011: * of the License, or any later version.
012: *
013: * This program is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: * GNU General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public License
019: * along with this program; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
021: */
022:
023: package org.gjt.sp.jedit.gui;
024:
025: //{{{ Imports
026: import java.awt.BorderLayout;
027: import java.awt.Component;
028: import java.awt.Container;
029: import java.awt.Window;
030: import java.awt.Dimension;
031: import java.awt.event.KeyListener;
032: import java.awt.event.MouseAdapter;
033: import java.awt.event.MouseEvent;
034: import java.beans.PropertyChangeEvent;
035: import java.beans.PropertyChangeListener;
036:
037: import javax.swing.Box;
038: import javax.swing.BoxLayout;
039: import javax.swing.JButton;
040: import javax.swing.JFrame;
041: import javax.swing.JPopupMenu;
042: import javax.swing.JSeparator;
043: import javax.swing.SwingUtilities;
044:
045: import org.gjt.sp.jedit.GUIUtilities;
046: import org.gjt.sp.jedit.jEdit;
047:
048: //}}}
049:
050: /**
051: * A container for dockable windows. This class should never be used
052: * directly.
053: * @version $Id: FloatingWindowContainer.java 10703 2007-09-21 13:14:03Z shlomy $
054: * @since jEdit 4.0pre1
055: */
056: public class FloatingWindowContainer extends JFrame implements
057: DockableWindowContainer, PropertyChangeListener {
058: String dockableName = null;
059:
060: //{{{ FloatingWindowContainer constructor
061: public FloatingWindowContainer(
062: DockableWindowManager dockableWindowManager, boolean clone) {
063: this .dockableWindowManager = dockableWindowManager;
064:
065: dockableWindowManager.addPropertyChangeListener(this );
066: this .clone = clone;
067: setIconImage(GUIUtilities.getPluginIcon());
068: setDefaultCloseOperation(DISPOSE_ON_CLOSE);
069:
070: Box caption = new Box(BoxLayout.X_AXIS);
071: caption.add(menu = new RolloverButton(GUIUtilities
072: .loadIcon("ToolbarMenu.gif")));
073: menu.addMouseListener(new MouseHandler());
074: menu.setToolTipText(jEdit.getProperty("docking.menu.label"));
075: Box separatorBox = new Box(BoxLayout.Y_AXIS);
076: separatorBox.add(Box.createVerticalStrut(3));
077: separatorBox.add(new JSeparator(JSeparator.HORIZONTAL));
078: separatorBox.add(Box.createVerticalStrut(3));
079: caption.add(separatorBox);
080: getContentPane().add(BorderLayout.NORTH, caption);
081:
082: } //}}}
083:
084: //{{{ register() method
085: public void register(DockableWindowManager.Entry entry) {
086: this .entry = entry;
087: dockableName = entry.factory.name;
088:
089: setTitle(entry.shortTitle());
090:
091: getContentPane().add(BorderLayout.CENTER, entry.win);
092:
093: pack();
094: Container parent = dockableWindowManager.getView();
095: GUIUtilities.loadGeometry(this , parent, dockableName);
096: GUIUtilities.addSizeSaver(this , parent, dockableName);
097: KeyListener listener = dockableWindowManager
098: .closeListener(dockableName);
099: addKeyListener(listener);
100: getContentPane().addKeyListener(listener);
101: menu.addKeyListener(listener);
102: entry.win.addKeyListener(listener);
103: setVisible(true);
104: if (!entry.win.isVisible())
105: entry.win.setVisible(true);
106: } //}}}
107:
108: //{{{ remove() method
109: public void remove(DockableWindowManager.Entry entry) {
110: dispose();
111: } //}}}
112:
113: //{{{ unregister() method
114: public void unregister(DockableWindowManager.Entry entry) {
115: this .entry = null;
116: entry.btn = null;
117: entry.container = null;
118: // Note: entry.win must not be reset, to enable the dockable
119: // instance to be moved instead of recreated if it uses the
120: // MOVABLE attribute.
121: super .dispose();
122: } //}}}
123:
124: //{{{ show() method
125: public void show(final DockableWindowManager.Entry entry) {
126: if (entry == null)
127: dispose();
128: else {
129: setTitle(entry.longTitle());
130: toFront();
131: requestFocus();
132: SwingUtilities.invokeLater(new Runnable() {
133: public void run() {
134: if (entry.win instanceof DefaultFocusComponent) {
135: ((DefaultFocusComponent) entry.win)
136: .focusOnDefaultComponent();
137: } else {
138: entry.win.requestFocus();
139: }
140: }
141: });
142: }
143: } //}}}
144:
145: //{{{ isVisible() method
146: public boolean isVisible(DockableWindowManager.Entry entry) {
147: return true;
148: } //}}}
149:
150: //{{{ dispose() method
151: public void dispose() {
152: entry.container = null;
153: entry.win = null;
154: super .dispose();
155: } //}}}
156:
157: //{{{ getDockableWindowManager() method
158: public DockableWindowManager getDockableWindowManager() {
159: return dockableWindowManager;
160: } //}}}
161:
162: //{{{ getMinimumSize() method
163: public Dimension getMinimumSize() {
164: return new Dimension(0, 0);
165: } //}}}
166:
167: //{{{ Private members
168: private DockableWindowManager dockableWindowManager;
169: private boolean clone;
170: private DockableWindowManager.Entry entry;
171: private JButton menu;
172:
173: //}}}
174:
175: //{{{ MouseHandler class
176: class MouseHandler extends MouseAdapter {
177: JPopupMenu popup;
178:
179: public void mousePressed(MouseEvent evt) {
180: if (popup != null && popup.isVisible())
181: popup.setVisible(false);
182: else {
183: popup = dockableWindowManager.createPopupMenu(
184: FloatingWindowContainer.this ,
185: entry.factory.name, clone);
186: GUIUtilities.showPopupMenu(popup, menu, menu.getX(),
187: menu.getY() + menu.getHeight(), false);
188: }
189: }
190: } //}}}
191:
192: public void propertyChange(PropertyChangeEvent evt) {
193: if (dockableName == null)
194: return;
195: String pn = evt.getPropertyName();
196: if (pn.startsWith(dockableName) && pn.endsWith("title"))
197: setTitle(evt.getNewValue().toString());
198: }
199:
200: }
|