[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;
|
---|
[3537] | 11 | import java.awt.Toolkit;
|
---|
[3543] | 12 | import java.awt.Window;
|
---|
[2711] | 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;
|
---|
[5078] | 19 | import javax.swing.JComponent;
|
---|
| 20 | import javax.swing.JFrame;
|
---|
| 21 | import javax.swing.KeyStroke;
|
---|
[2711] | 22 |
|
---|
[3535] | 23 | import org.openstreetmap.josm.Main;
|
---|
[3537] | 24 | import org.openstreetmap.josm.tools.PlatformHookWindows;
|
---|
[2711] | 25 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
| 26 |
|
---|
| 27 | public class FullscreenToggleAction extends JosmAction {
|
---|
| 28 | private final List<ButtonModel> buttonModels = new ArrayList<ButtonModel>();
|
---|
[5286] | 29 | private boolean selected;
|
---|
[2711] | 30 | private GraphicsDevice gd;
|
---|
[3543] | 31 | private Rectangle prevBounds;
|
---|
| 32 |
|
---|
[2711] | 33 | public FullscreenToggleAction() {
|
---|
| 34 | super(
|
---|
[4045] | 35 | tr("Fullscreen view"),
|
---|
[2711] | 36 | null, /* no icon */
|
---|
| 37 | tr("Toggle fullscreen view"),
|
---|
[4982] | 38 | Shortcut.registerShortcut("menu:view:fullscreen", tr("Toggle fullscreen view"),KeyEvent.VK_F11, Shortcut.DIRECT),
|
---|
[4139] | 39 | false /* register */
|
---|
[2711] | 40 | );
|
---|
[3757] | 41 | putValue("help", ht("/Action/FullscreenView"));
|
---|
[4139] | 42 | putValue("toolbar", "fullscreen");
|
---|
| 43 | Main.toolbar.register(this);
|
---|
[2711] | 44 | gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
|
---|
[5286] | 45 | selected = Main.pref.getBoolean("draw.fullscreen", false);
|
---|
[2711] | 46 | notifySelectedState();
|
---|
| 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) {
|
---|
[5286] | 63 | if (model.isSelected() != selected) {
|
---|
| 64 | model.setSelected(selected);
|
---|
[2711] | 65 | }
|
---|
| 66 | }
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | protected void toggleSelectedState() {
|
---|
[5286] | 70 | selected = !selected;
|
---|
| 71 | Main.pref.put("draw.fullscreen", selected);
|
---|
[2711] | 72 | notifySelectedState();
|
---|
[4139] | 73 | setMode();
|
---|
| 74 | }
|
---|
[2711] | 75 |
|
---|
[4139] | 76 | public void initial() {
|
---|
[5286] | 77 | if(selected)
|
---|
[4139] | 78 | setMode();
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | protected void setMode() {
|
---|
[5078] | 82 | JFrame frame = (JFrame) Main.parent;
|
---|
[3543] | 83 |
|
---|
| 84 | List<Window> visibleWindows = new ArrayList<Window>();
|
---|
| 85 | visibleWindows.add(frame);
|
---|
| 86 | for (Window w : Frame.getWindows()) {
|
---|
| 87 | if (w.isVisible() && w != frame) {
|
---|
| 88 | visibleWindows.add(w);
|
---|
| 89 | }
|
---|
| 90 | }
|
---|
[3551] | 91 |
|
---|
| 92 | frame.dispose();
|
---|
[5286] | 93 | frame.setUndecorated(selected);
|
---|
[3551] | 94 |
|
---|
[5286] | 95 | if (selected) {
|
---|
[3551] | 96 | prevBounds = frame.getBounds();
|
---|
| 97 | frame.setBounds(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
|
---|
| 98 | }
|
---|
[4203] | 99 |
|
---|
[3537] | 100 | // we cannot use hw-exclusive fullscreen mode in MS-Win, as long
|
---|
[5286] | 101 | // as josm throws out modal dialogs.
|
---|
[3537] | 102 | //
|
---|
| 103 | // the good thing is: fullscreen works without exclusive mode,
|
---|
| 104 | // since windows (or java?) draws the undecorated window full-
|
---|
| 105 | // screen by default (it's a simulated mode, but should be ok)
|
---|
| 106 | String exclusive = Main.pref.get("draw.fullscreen.exclusive-mode", "auto");
|
---|
[3543] | 107 | if ("true".equals(exclusive) || ("auto".equals(exclusive) && !(Main.platform instanceof PlatformHookWindows))) {
|
---|
[5286] | 108 | gd.setFullScreenWindow(selected ? frame : null);
|
---|
[3537] | 109 | }
|
---|
[3551] | 110 |
|
---|
[5286] | 111 | if (!selected && prevBounds != null) {
|
---|
[3551] | 112 | frame.setBounds(prevBounds);
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | for (Window wind : visibleWindows) {
|
---|
| 116 | wind.setVisible(true);
|
---|
| 117 | }
|
---|
[5286] | 118 |
|
---|
[5078] | 119 | // Free F10 key to allow it to be used by plugins, even after full screen (see #7502)
|
---|
[5286] | 120 | frame.getJMenuBar().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_F10, 0), "none");
|
---|
[2711] | 121 | }
|
---|
| 122 |
|
---|
[6084] | 123 | @Override
|
---|
[2711] | 124 | public void actionPerformed(ActionEvent e) {
|
---|
| 125 | toggleSelectedState();
|
---|
| 126 | }
|
---|
| 127 | }
|
---|