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