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