1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.actions;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.event.ActionEvent;
|
---|
7 | import java.awt.event.KeyEvent;
|
---|
8 | import java.util.ArrayList;
|
---|
9 | import java.util.List;
|
---|
10 |
|
---|
11 | import javax.swing.ButtonModel;
|
---|
12 |
|
---|
13 | /* For enabling fullscreen */
|
---|
14 | import java.awt.Frame;
|
---|
15 | import java.awt.GraphicsDevice;
|
---|
16 | import java.awt.GraphicsEnvironment;
|
---|
17 | import org.openstreetmap.josm.tools.PlatformHookUnixoid;
|
---|
18 |
|
---|
19 | import org.openstreetmap.josm.Main;
|
---|
20 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
21 |
|
---|
22 | public class FullscreenToggleAction extends JosmAction {
|
---|
23 | private final List<ButtonModel> buttonModels = new ArrayList<ButtonModel>();
|
---|
24 | //FIXME: replace with property Action.SELECTED_KEY when migrating to
|
---|
25 | // Java 6
|
---|
26 | private boolean selected;
|
---|
27 | private GraphicsDevice gd;
|
---|
28 | public FullscreenToggleAction() {
|
---|
29 | super(
|
---|
30 | tr("Fullscreen View"),
|
---|
31 | null, /* no icon */
|
---|
32 | tr("Toggle fullscreen view"),
|
---|
33 | Shortcut.registerShortcut("menu:view:fullscreen", tr("Toggle Fullscreen view"),KeyEvent.VK_F11, Shortcut.GROUP_DIRECT),
|
---|
34 | true /* register shortcut */
|
---|
35 | );
|
---|
36 | gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
|
---|
37 | selected = Main.pref.getBoolean("draw.fullscreen", false);
|
---|
38 | notifySelectedState();
|
---|
39 | }
|
---|
40 |
|
---|
41 | public boolean canFullscreen() {
|
---|
42 | /* We only support fullscreen, see
|
---|
43 | * http://lists.openstreetmap.org/pipermail/josm-dev/2009-March/002659.html
|
---|
44 | * for why
|
---|
45 | */
|
---|
46 | return Main.platform instanceof PlatformHookUnixoid && gd.isFullScreenSupported();
|
---|
47 | }
|
---|
48 |
|
---|
49 | public void addButtonModel(ButtonModel model) {
|
---|
50 | if (model != null && !buttonModels.contains(model)) {
|
---|
51 | buttonModels.add(model);
|
---|
52 | }
|
---|
53 | }
|
---|
54 |
|
---|
55 | public void removeButtonModel(ButtonModel model) {
|
---|
56 | if (model != null && buttonModels.contains(model)) {
|
---|
57 | buttonModels.remove(model);
|
---|
58 | }
|
---|
59 | }
|
---|
60 |
|
---|
61 | protected void notifySelectedState() {
|
---|
62 | for (ButtonModel model: buttonModels) {
|
---|
63 | if (model.isSelected() != selected) {
|
---|
64 | model.setSelected(selected);
|
---|
65 | }
|
---|
66 | }
|
---|
67 | }
|
---|
68 |
|
---|
69 | protected void toggleSelectedState() {
|
---|
70 | selected = !selected;
|
---|
71 | Main.pref.put("draw.fullscreen", selected);
|
---|
72 | notifySelectedState();
|
---|
73 |
|
---|
74 | if (selected) {
|
---|
75 | Frame frame = (Frame)Main.parent;
|
---|
76 | gd.setFullScreenWindow(frame);
|
---|
77 | } else {
|
---|
78 | gd.setFullScreenWindow(null);
|
---|
79 | }
|
---|
80 | }
|
---|
81 |
|
---|
82 | public void actionPerformed(ActionEvent e) {
|
---|
83 | toggleSelectedState();
|
---|
84 | }
|
---|
85 | }
|
---|