source: josm/trunk/src/org/openstreetmap/josm/actions/FullscreenToggleAction.java@ 2550

Last change on this file since 2550 was 2534, checked in by Gubaer, 14 years ago

applied #4033: patch by avar: "Fullscreen View" should be turned into a JosmAction (update)

File size: 2.7 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.event.ActionEvent;
7import java.awt.event.KeyEvent;
8import java.util.ArrayList;
9import java.util.List;
10
11import javax.swing.ButtonModel;
12
13/* For enabling fullscreen */
14import java.awt.Frame;
15import java.awt.GraphicsDevice;
16import java.awt.GraphicsEnvironment;
17import org.openstreetmap.josm.tools.PlatformHookUnixoid;
18
19import org.openstreetmap.josm.Main;
20import org.openstreetmap.josm.tools.Shortcut;
21
22public 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}
Note: See TracBrowser for help on using the repository browser.