[2711] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
| 2 | package org.openstreetmap.josm.actions;
|
---|
| 3 |
|
---|
[3757] | 4 | import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
|
---|
[2711] | 5 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
| 6 |
|
---|
[3535] | 7 | import java.awt.Frame;
|
---|
| 8 | import java.awt.GraphicsDevice;
|
---|
| 9 | import java.awt.GraphicsEnvironment;
|
---|
[3543] | 10 | import java.awt.Rectangle;
|
---|
| 11 | import java.awt.Window;
|
---|
[2711] | 12 | import java.awt.event.ActionEvent;
|
---|
| 13 | import java.awt.event.KeyEvent;
|
---|
| 14 | import java.util.ArrayList;
|
---|
| 15 | import java.util.List;
|
---|
| 16 |
|
---|
[5078] | 17 | import javax.swing.JComponent;
|
---|
| 18 | import javax.swing.JFrame;
|
---|
| 19 | import javax.swing.KeyStroke;
|
---|
[2711] | 20 |
|
---|
[3535] | 21 | import org.openstreetmap.josm.Main;
|
---|
[9576] | 22 | import org.openstreetmap.josm.gui.util.GuiHelper;
|
---|
[2711] | 23 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
| 24 |
|
---|
[6220] | 25 | /**
|
---|
| 26 | * This class toggles the full-screen mode.
|
---|
| 27 | * @since 2533
|
---|
| 28 | */
|
---|
| 29 | public class FullscreenToggleAction extends ToggleAction {
|
---|
[9067] | 30 | private final transient GraphicsDevice gd;
|
---|
[3543] | 31 | private Rectangle prevBounds;
|
---|
| 32 |
|
---|
[6220] | 33 | /**
|
---|
| 34 | * Constructs a new {@code FullscreenToggleAction}.
|
---|
| 35 | */
|
---|
[2711] | 36 | public FullscreenToggleAction() {
|
---|
[6220] | 37 | super(tr("Fullscreen view"),
|
---|
| 38 | null, /* no icon */
|
---|
| 39 | tr("Toggle fullscreen view"),
|
---|
[8510] | 40 | Shortcut.registerShortcut("menu:view:fullscreen", tr("Toggle fullscreen view"), KeyEvent.VK_F11, Shortcut.DIRECT),
|
---|
[6220] | 41 | false /* register */
|
---|
[2711] | 42 | );
|
---|
[3757] | 43 | putValue("help", ht("/Action/FullscreenView"));
|
---|
[4139] | 44 | putValue("toolbar", "fullscreen");
|
---|
| 45 | Main.toolbar.register(this);
|
---|
[2711] | 46 | gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
|
---|
[6220] | 47 | setSelected(Main.pref.getBoolean("draw.fullscreen", false));
|
---|
[2711] | 48 | notifySelectedState();
|
---|
| 49 | }
|
---|
| 50 |
|
---|
[6220] | 51 | @Override
|
---|
| 52 | public void actionPerformed(ActionEvent e) {
|
---|
[6327] | 53 | toggleSelectedState(e);
|
---|
[6220] | 54 | Main.pref.put("draw.fullscreen", isSelected());
|
---|
[2711] | 55 | notifySelectedState();
|
---|
[4139] | 56 | setMode();
|
---|
| 57 | }
|
---|
[2711] | 58 |
|
---|
[6220] | 59 | /**
|
---|
| 60 | * To call if this action must be initially run at JOSM startup.
|
---|
| 61 | */
|
---|
[4139] | 62 | public void initial() {
|
---|
[6220] | 63 | if (isSelected()) {
|
---|
[4139] | 64 | setMode();
|
---|
[6220] | 65 | }
|
---|
[4139] | 66 | }
|
---|
| 67 |
|
---|
| 68 | protected void setMode() {
|
---|
[5078] | 69 | JFrame frame = (JFrame) Main.parent;
|
---|
[3543] | 70 |
|
---|
[7005] | 71 | List<Window> visibleWindows = new ArrayList<>();
|
---|
[3543] | 72 | visibleWindows.add(frame);
|
---|
| 73 | for (Window w : Frame.getWindows()) {
|
---|
| 74 | if (w.isVisible() && w != frame) {
|
---|
| 75 | visibleWindows.add(w);
|
---|
| 76 | }
|
---|
| 77 | }
|
---|
[7335] | 78 |
|
---|
[6220] | 79 | boolean selected = isSelected();
|
---|
[3551] | 80 |
|
---|
| 81 | frame.dispose();
|
---|
[5286] | 82 | frame.setUndecorated(selected);
|
---|
[3551] | 83 |
|
---|
[5286] | 84 | if (selected) {
|
---|
[3551] | 85 | prevBounds = frame.getBounds();
|
---|
[9576] | 86 | frame.setBounds(new Rectangle(GuiHelper.getScreenSize()));
|
---|
[3551] | 87 | }
|
---|
[4203] | 88 |
|
---|
[3537] | 89 | // we cannot use hw-exclusive fullscreen mode in MS-Win, as long
|
---|
[5286] | 90 | // as josm throws out modal dialogs.
|
---|
[3537] | 91 | //
|
---|
| 92 | // the good thing is: fullscreen works without exclusive mode,
|
---|
| 93 | // since windows (or java?) draws the undecorated window full-
|
---|
| 94 | // screen by default (it's a simulated mode, but should be ok)
|
---|
| 95 | String exclusive = Main.pref.get("draw.fullscreen.exclusive-mode", "auto");
|
---|
[7335] | 96 | if ("true".equals(exclusive) || ("auto".equals(exclusive) && !Main.isPlatformWindows())) {
|
---|
[5286] | 97 | gd.setFullScreenWindow(selected ? frame : null);
|
---|
[3537] | 98 | }
|
---|
[3551] | 99 |
|
---|
[5286] | 100 | if (!selected && prevBounds != null) {
|
---|
[3551] | 101 | frame.setBounds(prevBounds);
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | for (Window wind : visibleWindows) {
|
---|
| 105 | wind.setVisible(true);
|
---|
| 106 | }
|
---|
[5286] | 107 |
|
---|
[5078] | 108 | // Free F10 key to allow it to be used by plugins, even after full screen (see #7502)
|
---|
[5286] | 109 | frame.getJMenuBar().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_F10, 0), "none");
|
---|
[2711] | 110 | }
|
---|
| 111 | }
|
---|