Search in sources :

Example 1 with GridEditPanel

use of de.gurkenlabs.utiliti.swing.dialogs.GridEditPanel in project litiengine by gurkenlabs.

the class Program method initViewMenu.

private static Menu initViewMenu() {
    Menu mnView = new Menu(Resources.get("menu_view"));
    CheckboxMenuItem snapToGrid = new CheckboxMenuItem(Resources.get("menu_snapGrid"));
    snapToGrid.setState(userPreferences.isSnapGrid());
    EditorScreen.instance().getMapComponent().setSnapToGrid(snapToGrid.getState());
    snapToGrid.addItemListener(e -> {
        EditorScreen.instance().getMapComponent().setSnapToGrid(snapToGrid.getState());
        userPreferences.setSnapGrid(snapToGrid.getState());
    });
    CheckboxMenuItem renderGrid = new CheckboxMenuItem(Resources.get("menu_renderGrid"));
    renderGrid.setState(userPreferences.isShowGrid());
    EditorScreen.instance().getMapComponent().setRenderGrid(renderGrid.getState());
    renderGrid.setShortcut(new MenuShortcut(KeyEvent.VK_G));
    renderGrid.addItemListener(e -> {
        EditorScreen.instance().getMapComponent().setRenderGrid(renderGrid.getState());
        userPreferences.setShowGrid(renderGrid.getState());
    });
    CheckboxMenuItem renderCollision = new CheckboxMenuItem(Resources.get("menu_renderCollisionBoxes"));
    renderCollision.setState(userPreferences.isRenderBoundingBoxes());
    EditorScreen.instance().getMapComponent().setRenderCollisionBoxes(renderCollision.getState());
    renderCollision.setShortcut(new MenuShortcut(KeyEvent.VK_H));
    renderCollision.addItemListener(e -> {
        EditorScreen.instance().getMapComponent().setRenderCollisionBoxes(renderCollision.getState());
        userPreferences.setRenderBoundingBoxes(renderCollision.getState());
    });
    MenuItem setGrid = new MenuItem(Resources.get("menu_gridSize"));
    setGrid.addActionListener(a -> {
        GridEditPanel panel = new GridEditPanel(EditorScreen.instance().getMapComponent().getGridSize());
        int option = JOptionPane.showConfirmDialog(Game.getScreenManager().getRenderComponent(), panel, Resources.get("menu_gridSettings"), JOptionPane.DEFAULT_OPTION);
        if (option == JOptionPane.OK_OPTION) {
            EditorScreen.instance().getMapComponent().setGridSize(panel.getGridSize());
        }
    });
    MenuItem zoomIn = new MenuItem(Resources.get("menu_zoomIn"));
    zoomIn.setShortcut(new MenuShortcut(KeyEvent.VK_PLUS));
    zoomIn.addActionListener(a -> EditorScreen.instance().getMapComponent().zoomIn());
    MenuItem zoomOut = new MenuItem(Resources.get("menu_zoomOut"));
    zoomOut.setShortcut(new MenuShortcut(KeyEvent.VK_MINUS));
    zoomOut.addActionListener(a -> EditorScreen.instance().getMapComponent().zoomOut());
    mnView.add(snapToGrid);
    mnView.add(renderGrid);
    mnView.add(renderCollision);
    mnView.add(setGrid);
    mnView.addSeparator();
    mnView.add(zoomIn);
    mnView.add(zoomOut);
    return mnView;
}
Also used : CheckboxMenuItem(java.awt.CheckboxMenuItem) GridEditPanel(de.gurkenlabs.utiliti.swing.dialogs.GridEditPanel) CheckboxMenuItem(java.awt.CheckboxMenuItem) MenuItem(java.awt.MenuItem) JMenuItem(javax.swing.JMenuItem) PopupMenu(java.awt.PopupMenu) Menu(java.awt.Menu) JPopupMenu(javax.swing.JPopupMenu) MenuShortcut(java.awt.MenuShortcut)

Aggregations

GridEditPanel (de.gurkenlabs.utiliti.swing.dialogs.GridEditPanel)1 CheckboxMenuItem (java.awt.CheckboxMenuItem)1 Menu (java.awt.Menu)1 MenuItem (java.awt.MenuItem)1 MenuShortcut (java.awt.MenuShortcut)1 PopupMenu (java.awt.PopupMenu)1 JMenuItem (javax.swing.JMenuItem)1 JPopupMenu (javax.swing.JPopupMenu)1