Ticket #2279: FullScreen-2.patch

File FullScreen-2.patch, 2.5 KB (added by avarab@…, 17 years ago)

Add option to full screen JOSM to the main menu: Improved patch

  • src/org/openstreetmap/josm/gui/MainMenu.java

     
    1414import javax.swing.JMenuItem;
    1515import javax.swing.KeyStroke;
    1616
     17/* For the fullscreen action */
     18import java.awt.Frame;
     19import java.awt.GraphicsEnvironment;
     20import java.awt.GraphicsDevice;
     21import org.openstreetmap.josm.tools.PlatformHookUnixoid;
     22
    1723import org.openstreetmap.josm.Main;
    1824import org.openstreetmap.josm.actions.AboutAction;
    1925import org.openstreetmap.josm.actions.AddNodeAction;
     
    228234            JosmAction autoScaleAction = new AutoScaleAction(mode);
    229235            add(viewMenu, autoScaleAction);
    230236        }
     237
     238        /// Fullscreen
     239        String os = System.getProperty("os.name");
     240        // See http://lists.openstreetmap.org/pipermail/josm-dev/2009-March/002659.html for why I'm doing this
     241        boolean canFullScreen = Main.platform instanceof PlatformHookUnixoid;
     242
     243        if (canFullScreen) {
     244            // TODO move code to an "action" like the others?
     245            final JCheckBoxMenuItem fullscreen = new JCheckBoxMenuItem(tr("Full Screen"));
     246            fullscreen.setSelected(Main.pref.getBoolean("draw.fullscreen", false));
     247            fullscreen.setAccelerator(Shortcut.registerShortcut("menu:view:fullscreen", tr("Toggle Full Screen view"),
     248                    KeyEvent.VK_F11, Shortcut.GROUP_DIRECT).getKeyStroke());
     249            fullscreen.addActionListener(new ActionListener() {
     250                public void actionPerformed(ActionEvent ev) {
     251                    Main.pref.put("draw.fullscreen", fullscreen.isSelected());
     252
     253                    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
     254                    GraphicsDevice gd = ge.getDefaultScreenDevice();
     255
     256                    Frame frame = (Frame)Main.parent;
     257                    boolean FullScreenSupported = gd.isFullScreenSupported();
     258
     259                    if (Main.pref.getBoolean("draw.fullscreen")) {
     260                        if (FullScreenSupported)
     261                            gd.setFullScreenWindow(frame);
     262                    } else {
     263                        if (FullScreenSupported)
     264                            gd.setFullScreenWindow(null);
     265                    }
     266                }
     267            });
     268            viewMenu.addSeparator();
     269            viewMenu.add(fullscreen);
     270        }
    231271        add(viewMenu, KeyEvent.VK_V, "view");
    232272
    233273        add(toolsMenu, splitWay);