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.Toolkit;
|
---|
12 | import java.awt.Window;
|
---|
13 | import java.awt.event.ActionEvent;
|
---|
14 | import java.awt.event.KeyEvent;
|
---|
15 | import java.util.ArrayList;
|
---|
16 | import java.util.List;
|
---|
17 |
|
---|
18 | import javax.swing.ButtonModel;
|
---|
19 |
|
---|
20 | import org.openstreetmap.josm.Main;
|
---|
21 | import org.openstreetmap.josm.tools.PlatformHookUnixoid;
|
---|
22 | import org.openstreetmap.josm.tools.PlatformHookWindows;
|
---|
23 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
24 |
|
---|
25 | public class FullscreenToggleAction extends JosmAction {
|
---|
26 | private final List<ButtonModel> buttonModels = new ArrayList<ButtonModel>();
|
---|
27 | //FIXME: replace with property Action.SELECTED_KEY when migrating to
|
---|
28 | // Java 6
|
---|
29 | private boolean selected;
|
---|
30 | private GraphicsDevice gd;
|
---|
31 | private Rectangle prevBounds;
|
---|
32 |
|
---|
33 | public FullscreenToggleAction() {
|
---|
34 | super(
|
---|
35 | tr("Fullscreen View"),
|
---|
36 | null, /* no icon */
|
---|
37 | tr("Toggle fullscreen view"),
|
---|
38 | Shortcut.registerShortcut("menu:view:fullscreen", tr("Toggle Fullscreen view"),KeyEvent.VK_F11, Shortcut.GROUP_DIRECT),
|
---|
39 | true /* register shortcut */
|
---|
40 | );
|
---|
41 | putValue("help", ht("/Action/FullscreenView"));
|
---|
42 | gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
|
---|
43 | selected = Main.pref.getBoolean("draw.fullscreen", false);
|
---|
44 | notifySelectedState();
|
---|
45 | }
|
---|
46 |
|
---|
47 | public boolean canFullscreen() {
|
---|
48 | /* We only support fullscreen, see
|
---|
49 | * http://lists.openstreetmap.org/pipermail/josm-dev/2009-March/002659.html
|
---|
50 | * for why
|
---|
51 | */
|
---|
52 | return Main.platform instanceof PlatformHookUnixoid && gd.isFullScreenSupported();
|
---|
53 | }
|
---|
54 |
|
---|
55 | public void addButtonModel(ButtonModel model) {
|
---|
56 | if (model != null && !buttonModels.contains(model)) {
|
---|
57 | buttonModels.add(model);
|
---|
58 | }
|
---|
59 | }
|
---|
60 |
|
---|
61 | public void removeButtonModel(ButtonModel model) {
|
---|
62 | if (model != null && buttonModels.contains(model)) {
|
---|
63 | buttonModels.remove(model);
|
---|
64 | }
|
---|
65 | }
|
---|
66 |
|
---|
67 | protected void notifySelectedState() {
|
---|
68 | for (ButtonModel model: buttonModels) {
|
---|
69 | if (model.isSelected() != selected) {
|
---|
70 | model.setSelected(selected);
|
---|
71 | }
|
---|
72 | }
|
---|
73 | }
|
---|
74 |
|
---|
75 | protected void toggleSelectedState() {
|
---|
76 | selected = !selected;
|
---|
77 | Main.pref.put("draw.fullscreen", selected);
|
---|
78 | notifySelectedState();
|
---|
79 |
|
---|
80 | Frame frame = (Frame) Main.parent;
|
---|
81 |
|
---|
82 | List<Window> visibleWindows = new ArrayList<Window>();
|
---|
83 | visibleWindows.add(frame);
|
---|
84 | for (Window w : Frame.getWindows()) {
|
---|
85 | if (w.isVisible() && w != frame) {
|
---|
86 | visibleWindows.add(w);
|
---|
87 | }
|
---|
88 | }
|
---|
89 |
|
---|
90 | frame.dispose();
|
---|
91 | frame.setUndecorated(selected);
|
---|
92 |
|
---|
93 | if (selected) {
|
---|
94 | prevBounds = frame.getBounds();
|
---|
95 | frame.setBounds(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
|
---|
96 | }
|
---|
97 |
|
---|
98 | // we cannot use hw-exclusive fullscreen mode in MS-Win, as long
|
---|
99 | // as josm throws out modal dialogs, see here:
|
---|
100 | // http://forums.sun.com/thread.jspa?threadID=5351882
|
---|
101 | //
|
---|
102 | // the good thing is: fullscreen works without exclusive mode,
|
---|
103 | // since windows (or java?) draws the undecorated window full-
|
---|
104 | // screen by default (it's a simulated mode, but should be ok)
|
---|
105 | String exclusive = Main.pref.get("draw.fullscreen.exclusive-mode", "auto");
|
---|
106 | if ("true".equals(exclusive) || ("auto".equals(exclusive) && !(Main.platform instanceof PlatformHookWindows))) {
|
---|
107 | gd.setFullScreenWindow(selected ? frame : null);
|
---|
108 | }
|
---|
109 |
|
---|
110 | if (!selected && prevBounds != null) {
|
---|
111 | frame.setBounds(prevBounds);
|
---|
112 | }
|
---|
113 |
|
---|
114 | for (Window wind : visibleWindows) {
|
---|
115 | wind.setVisible(true);
|
---|
116 | }
|
---|
117 | }
|
---|
118 |
|
---|
119 | public void actionPerformed(ActionEvent e) {
|
---|
120 | toggleSelectedState();
|
---|
121 | }
|
---|
122 | }
|
---|