/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2002 Sun * Microsystems, Inc. All Rights Reserved. */ package fullscreeneditor; import java.awt.BorderLayout; import java.awt.GraphicsEnvironment; import java.awt.Image; import java.awt.Toolkit; import java.awt.Window; import java.awt.event.ActionEvent; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import javax.swing.AbstractAction; import javax.swing.ActionMap; import javax.swing.JComponent; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.KeyStroke; import javax.swing.WindowConstants; import org.openide.util.HelpCtx; import org.openide.util.NbBundle; import org.openide.util.actions.CallableSystemAction; import org.openide.windows.*; public class FullScreenAction extends CallableSystemAction implements PropertyChangeListener, WindowListener { private static final class FakeWM extends WindowManager { public void open(TopComponent t) { componentOpenNotify(t); componentShowing(t); } public void close(TopComponent t) { componentHidden(t); componentCloseNotify(t); } public void addPropertyChangeListener(PropertyChangeListener l) { throw new IllegalStateException(); } protected WindowManager.Component createTopComponentManager(TopComponent c) { throw new IllegalStateException(); } public Workspace createWorkspace(String name, String displayName) { throw new IllegalStateException(); } public Workspace findWorkspace(String name) { throw new IllegalStateException(); } public Workspace getCurrentWorkspace() { throw new IllegalStateException(); } public java.awt.Frame getMainWindow() { throw new IllegalStateException(); } public Workspace[] getWorkspaces() { throw new IllegalStateException(); } public void removePropertyChangeListener(PropertyChangeListener l) { throw new IllegalStateException(); } public void setWorkspaces(Workspace[] workspaces) { throw new IllegalStateException(); } public void updateUI() { throw new IllegalStateException(); } public TopComponent.Registry componentRegistry() { throw new IllegalStateException(); } } protected void initialize() { super.initialize(); // Cf. org.netbeans.core.windows.frames.NbFocusManager and // org.netbeans.core.windows.frames.ShortcutAndMenuKeyEventProcessor putProperty("OpenIDE-Transmodal-Action", Boolean.TRUE); // NOI18N } private Window f = null; private TopComponent nue = null; public void performAction() { if (f == null) { TopComponent tc = TopComponent.getRegistry().getActivated(); if (tc instanceof TopComponent.Cloneable) { nue = ((TopComponent.Cloneable)tc).cloneComponent(); // JFrame f = new JFrame(nue.getName()); JDialog f = new JDialog(WindowManager.getDefault().getMainWindow(), nue.getName(), false); f.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); f.setUndecorated(true); nue.addPropertyChangeListener(this); f.getContentPane().add(nue, BorderLayout.CENTER); /* f.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("control shift typed F11"), "fullscreen"); f.getRootPane().getActionMap().put("fullscreen", this); */ f.setVisible(true); /* Image i = nue.getIcon(); if (i != null) f.setIconImage(i); */ new FakeWM().open(nue); GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(f); nue.requestFocus(); TopComponent.getRegistry().addPropertyChangeListener(this); f.addWindowListener(this); this.f = f; } else { Toolkit.getDefaultToolkit().beep(); } } else { disposeIt(); } } private void disposeIt() { nue.removePropertyChangeListener(this); TopComponent.getRegistry().removePropertyChangeListener(this); f.removeWindowListener(this); GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(null); new FakeWM().close(nue); f.setVisible(false); f.dispose(); nue = null; f = null; } public String getName() { return NbBundle.getMessage(FullScreenAction.class, "LBL_Action"); } public HelpCtx getHelpCtx() { return HelpCtx.DEFAULT_HELP; } public void propertyChange(PropertyChangeEvent evt) { if (f != null && nue != null) { if ("name".equals(evt.getPropertyName())) { ((JDialog)f).setTitle(nue.getName()); } else if (TopComponent.Registry.PROP_ACTIVATED.equals(evt.getPropertyName())) { /* does not seem to work (grey screen): TopComponent act = TopComponent.getRegistry().getActivated(); if (act != nue && act instanceof TopComponent.Cloneable) { new FakeWM().close(nue); nue.removePropertyChangeListener(this); TopComponent nue2 = ((TopComponent.Cloneable)act).cloneComponent(); f.setTitle(nue2.getName()); Image i = nue2.getIcon(); if (i != null) f.setIconImage(i); nue2.addPropertyChangeListener(this); f.getContentPane().remove(nue); f.getContentPane().add(nue2, BorderLayout.CENTER); new FakeWM().open(nue2); nue2.requestFocus(); nue = nue2; } */ } } } public void windowClosing(WindowEvent e) { disposeIt(); } public void windowDeactivated(WindowEvent e) { } public void windowDeiconified(WindowEvent e) { } public void windowIconified(WindowEvent e) { } public void windowOpened(WindowEvent e) { } public void windowActivated(WindowEvent e) { } public void windowClosed(WindowEvent e) { } }