1 22 23 package org.gjt.sp.jedit.gui; 24 25 import java.awt.BorderLayout ; 27 import java.awt.Component ; 28 import java.awt.Container ; 29 import java.awt.Window ; 30 import java.awt.Dimension ; 31 import java.awt.event.KeyListener ; 32 import java.awt.event.MouseAdapter ; 33 import java.awt.event.MouseEvent ; 34 import java.beans.PropertyChangeEvent ; 35 import java.beans.PropertyChangeListener ; 36 37 import javax.swing.Box ; 38 import javax.swing.BoxLayout ; 39 import javax.swing.JButton ; 40 import javax.swing.JFrame ; 41 import javax.swing.JPopupMenu ; 42 import javax.swing.JSeparator ; 43 import javax.swing.SwingUtilities ; 44 45 import org.gjt.sp.jedit.GUIUtilities; 46 import org.gjt.sp.jedit.jEdit; 47 49 55 public class FloatingWindowContainer extends JFrame implements DockableWindowContainer, 56 PropertyChangeListener 57 { 58 String dockableName = null; 59 public FloatingWindowContainer(DockableWindowManager dockableWindowManager, 61 boolean clone) 62 { 63 this.dockableWindowManager = dockableWindowManager; 64 65 dockableWindowManager.addPropertyChangeListener(this); 66 this.clone = clone; 67 setIconImage(GUIUtilities.getPluginIcon()); 68 setDefaultCloseOperation(DISPOSE_ON_CLOSE); 69 70 Box caption = new Box (BoxLayout.X_AXIS); 71 caption.add(menu = new RolloverButton(GUIUtilities 72 .loadIcon("ToolbarMenu.gif"))); 73 menu.addMouseListener(new MouseHandler()); 74 menu.setToolTipText(jEdit.getProperty("docking.menu.label")); 75 Box separatorBox = new Box (BoxLayout.Y_AXIS); 76 separatorBox.add(Box.createVerticalStrut(3)); 77 separatorBox.add(new JSeparator (JSeparator.HORIZONTAL)); 78 separatorBox.add(Box.createVerticalStrut(3)); 79 caption.add(separatorBox); 80 getContentPane().add(BorderLayout.NORTH,caption); 81 82 83 } 85 public void register(DockableWindowManager.Entry entry) 87 { 88 this.entry = entry; 89 dockableName = entry.factory.name; 90 91 setTitle(entry.shortTitle()); 92 93 getContentPane().add(BorderLayout.CENTER,entry.win); 94 95 pack(); 96 Container parent = dockableWindowManager.getView(); 97 GUIUtilities.loadGeometry(this, parent, dockableName); 98 GUIUtilities.addSizeSaver(this, parent, dockableName); 99 KeyListener listener = dockableWindowManager.closeListener(dockableName); 100 addKeyListener(listener); 101 getContentPane().addKeyListener(listener); 102 menu.addKeyListener(listener); 103 entry.win.addKeyListener(listener); 104 setVisible(true); 105 } 107 public void remove(DockableWindowManager.Entry entry) 109 { 110 entry.container = null; 111 dispose(); 112 } 114 public void unregister(DockableWindowManager.Entry entry) 116 { 117 dispose(); 118 } 120 public void show(final DockableWindowManager.Entry entry) 122 { 123 if(entry == null) 124 dispose(); 125 else 126 { 127 setTitle(entry.longTitle()); 128 toFront(); 129 requestFocus(); 130 SwingUtilities.invokeLater(new Runnable () 131 { 132 public void run() 133 { 134 if(entry.win instanceof DefaultFocusComponent) 135 { 136 ((DefaultFocusComponent)entry.win) 137 .focusOnDefaultComponent(); 138 } 139 else 140 { 141 entry.win.requestFocus(); 142 } 143 } 144 }); 145 } 146 } 148 public boolean isVisible(DockableWindowManager.Entry entry) 150 { 151 return true; 152 } 154 public void dispose() 156 { 157 entry.container = null; 158 entry.win = null; 159 super.dispose(); 160 } 162 public DockableWindowManager getDockableWindowManager() 164 { 165 return dockableWindowManager; 166 } 168 public Dimension getMinimumSize() 170 { 171 return new Dimension (0,0); 172 } 174 private DockableWindowManager dockableWindowManager; 176 private boolean clone; 177 private DockableWindowManager.Entry entry; 178 private JButton menu; 179 181 class MouseHandler extends MouseAdapter 183 { 184 JPopupMenu popup; 185 186 public void mousePressed(MouseEvent evt) 187 { 188 if(popup != null && popup.isVisible()) 189 popup.setVisible(false); 190 else 191 { 192 popup = dockableWindowManager.createPopupMenu( 193 FloatingWindowContainer.this, 194 entry.factory.name,clone); 195 GUIUtilities.showPopupMenu(popup, 196 menu,menu.getX(),menu.getY() + menu.getHeight(), 197 false); 198 } 199 } 200 } public void propertyChange(PropertyChangeEvent evt) 202 { 203 if (dockableName == null) return; 204 String pn = evt.getPropertyName(); 205 if (pn.startsWith(dockableName) && pn.endsWith("title")) 206 setTitle(evt.getNewValue().toString()); 207 } 208 209 } 210 211 | Popular Tags |