Example usage for javax.swing ActionMap put

List of usage examples for javax.swing ActionMap put

Introduction

In this page you can find the example usage for javax.swing ActionMap put.

Prototype

public void put(Object key, Action action) 

Source Link

Document

Adds a binding for key to action.

Usage

From source file:es.darkhogg.hazelnutt.EditorFrame.java

private void initializeGui() {
    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    setBounds(100, 100, 640, 480);/*w w w  . j a  va  2s.c  o  m*/

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent arg0) {
            actionExit();
        }
    });

    fileChooser = new JFileChooser();
    //fileChooser.setFileFilter( hlfFileFilter );

    hlfFileChooser = new JFileChooser();
    hlfFileChooser.setFileFilter(hlfFileFilter);

    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);

    JMenu mnFile = new JMenu("File");
    mnFile.setMnemonic('F');
    menuBar.add(mnFile);

    menuLoadRom = new JMenuItem("Load ROM...");
    menuLoadRom.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_MASK));
    menuLoadRom.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionOpenRom(null);
        }
    });
    menuLoadRom.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_open.png")));
    menuLoadRom.setMnemonic('O');
    mnFile.add(menuLoadRom);

    menuSaveRom = new JMenuItem("Save ROM");
    menuSaveRom.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionSaveRom();
        }
    });
    menuSaveRom.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_save.png")));
    menuSaveRom.setMnemonic('S');
    menuSaveRom.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK));
    mnFile.add(menuSaveRom);

    menuSaveRomAs = new JMenuItem("Save ROM As...");
    menuSaveRomAs.setMnemonic('a');
    menuSaveRomAs.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.CTRL_MASK));
    menuSaveRomAs.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionSaveRomAs();
        }
    });
    menuSaveRomAs
            .setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_save_as.png")));
    mnFile.add(menuSaveRomAs);

    mnFile.addSeparator();

    menuLoadLevel = new JMenuItem("Load Level...");
    menuLoadLevel.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0));
    menuLoadLevel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionLoadLevel();
        }
    });
    menuLoadLevel.setIcon(
            new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_load_level.png")));
    menuLoadLevel.setMnemonic('L');
    mnFile.add(menuLoadLevel);

    menuReloadLevel = new JMenuItem("Reload Level");
    menuReloadLevel.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F6, 0));
    menuReloadLevel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionReloadLevel();
        }
    });
    menuReloadLevel.setMnemonic('R');
    menuReloadLevel.setIcon(
            new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_reload_level.png")));
    mnFile.add(menuReloadLevel);

    menuSaveLevel = new JMenuItem("Save Level");
    menuSaveLevel.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F7, 0));
    menuSaveLevel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionSaveLevel();
        }
    });
    menuSaveLevel.setIcon(
            new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_save_level.png")));
    menuSaveLevel.setMnemonic('v');

    mnFile.add(menuSaveLevel);

    //*
    mnFile.addSeparator();

    menuImportLevel = new JMenuItem("Import Level...");
    menuImportLevel.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0));
    menuImportLevel.setMnemonic('i');
    menuImportLevel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionImportLevel();
        }
    });
    menuImportLevel
            .setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_import.png")));
    mnFile.add(menuImportLevel);

    menuExportLevel = new JMenuItem("Export Level...");
    menuExportLevel.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0));
    menuExportLevel.setMnemonic('e');
    menuExportLevel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionExportLevel();
        }
    });
    menuExportLevel
            .setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_export.png")));
    mnFile.add(menuExportLevel);
    //*/

    mnFile.addSeparator();

    menuExit = new JMenuItem("Exit");
    menuExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0));
    menuExit.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_exit.png")));
    menuExit.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            actionExit();
        }
    });

    menuRecentFiles = new JMenu("Recent Files...");
    mnFile.add(menuRecentFiles);

    mnFile.addSeparator();
    menuExit.setMnemonic('X');
    mnFile.add(menuExit);

    JMenu mnEdit = new JMenu("Edit");
    mnEdit.setMnemonic('E');
    menuBar.add(mnEdit);

    menuViewSpawn = new JCheckBoxMenuItem("View Spawn Point");
    menuViewSpawn.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, 0));
    menuViewSpawn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionToggle(false);
        }
    });

    menuClearLevel = new JMenuItem("Clear Level");
    menuClearLevel.setMnemonic('c');
    menuClearLevel.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK));
    menuClearLevel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionClearLevel();
        }
    });
    menuClearLevel.setIcon(
            new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_clear_level.png")));
    mnEdit.add(menuClearLevel);

    mnEdit.addSeparator();

    menuViewSpawn
            .setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_spawn.png")));
    menuViewSpawn.setMnemonic('S');
    menuViewSpawn.setSelected(true);
    mnEdit.add(menuViewSpawn);

    menuViewItems = new JCheckBoxMenuItem("View Items");
    menuViewItems.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_2, 0));
    menuViewItems.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionToggle(false);
        }
    });
    menuViewItems.setSelected(true);
    menuViewItems
            .setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_items.png")));
    menuViewItems.setMnemonic('I');
    mnEdit.add(menuViewItems);

    menuViewDoorItems = new JCheckBoxMenuItem("View Door Items");
    menuViewDoorItems.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_3, 0));
    menuViewDoorItems.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionToggle(false);
        }
    });
    menuViewDoorItems.setSelected(true);
    menuViewDoorItems.setIcon(
            new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_door_items.png")));
    menuViewDoorItems.setMnemonic('D');
    mnEdit.add(menuViewDoorItems);

    menuViewEnemies = new JCheckBoxMenuItem("View Enemies");
    menuViewEnemies.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_4, 0));
    menuViewEnemies.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionToggle(false);
        }
    });
    menuViewEnemies.setSelected(true);
    menuViewEnemies
            .setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_enemies.png")));
    menuViewEnemies.setMnemonic('E');
    mnEdit.add(menuViewEnemies);

    menuViewTypes = new JCheckBoxMenuItem("View Combo Types");
    menuViewTypes.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_5, 0));
    menuViewTypes.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionToggle(false);
        }
    });
    menuViewTypes.setSelected(true);
    menuViewTypes.setIcon(
            new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_combo_infos.png")));
    menuViewTypes.setMnemonic('C');
    mnEdit.add(menuViewTypes);

    mnEdit.addSeparator();

    scaleMenuItem = new JCheckBoxMenuItem("Scale Level Display");
    scaleMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_6, 0));
    scaleMenuItem.setMnemonic('l');
    scaleMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionScale(false);
        }
    });
    scaleMenuItem.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_x2.png")));
    mnEdit.add(scaleMenuItem);

    gridMenuItem = new JCheckBoxMenuItem("Display grid");
    gridMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_7, 0));
    gridMenuItem.setMnemonic('G');
    gridMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionGrid(false);
        }
    });
    gridMenuItem.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_grid.png")));
    mnEdit.add(gridMenuItem);

    //mnEdit.addSeparator();

    mntmPreferences = new JMenuItem("Preferences...");
    mntmPreferences.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionPreferences();
        }
    });
    mntmPreferences.setMnemonic('P');
    mntmPreferences.setIcon(
            new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_preferences.png")));
    //mnEdit.add(mntmPreferences);

    mnHelp = new JMenu("Help");
    mnHelp.setMnemonic('H');
    menuBar.add(mnHelp);

    mntmCheckUpdates = new JMenuItem("Check for Updates...");
    mntmCheckUpdates.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_U, InputEvent.CTRL_MASK));
    mntmCheckUpdates.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionCheckUpdates();
        }
    });
    mntmCheckUpdates.setMnemonic('c');
    mntmCheckUpdates
            .setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_update.png")));
    mnHelp.add(mntmCheckUpdates);

    mntmAbout = new JMenuItem("Readme...");
    mntmAbout.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0));
    mntmAbout.setMnemonic('r');
    mntmAbout.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/about.png")));
    mntmAbout.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionAbout();
        }
    });
    mnHelp.addSeparator();
    mnHelp.add(mntmAbout);

    contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    contentPane.setLayout(new BorderLayout(0, 0));
    setContentPane(contentPane);

    JToolBar toolBar = new JToolBar();
    toolBar.setRollover(true);
    toolBar.setFloatable(false);
    contentPane.add(toolBar, BorderLayout.NORTH);

    barLoadRom = new JButton("");
    barLoadRom.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionOpenRom(null);
        }
    });
    barLoadRom.setToolTipText("Open");
    barLoadRom.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_open.png")));
    toolBar.add(barLoadRom);

    barSaveRom = new JButton("");
    barSaveRom.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionSaveRom();
        }
    });
    barSaveRom.setToolTipText("Save");
    barSaveRom.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_save.png")));
    toolBar.add(barSaveRom);

    toolBar.addSeparator();

    barImportLevel = new JButton("");
    barImportLevel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionImportLevel();
        }
    });
    barImportLevel.setToolTipText("Import Level");
    barImportLevel
            .setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_import.png")));
    toolBar.add(barImportLevel);

    barExportLevel = new JButton("");
    barExportLevel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionExportLevel();
        }
    });
    barExportLevel.setToolTipText("Export Level");
    barExportLevel
            .setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_export.png")));
    toolBar.add(barExportLevel);

    toolBar.addSeparator();

    barLoadLevel = new JButton("");
    barLoadLevel.setToolTipText("Load Level");
    barLoadLevel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionLoadLevel();
        }
    });
    barLoadLevel.setIcon(
            new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_load_level.png")));
    toolBar.add(barLoadLevel);

    barReloadLevel = new JButton("");
    barReloadLevel.setToolTipText("Reload Current Level");
    barReloadLevel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionReloadLevel();
        }
    });
    barReloadLevel.setIcon(
            new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_reload_level.png")));
    toolBar.add(barReloadLevel);

    barSaveLevel = new JButton("");
    barSaveLevel.setToolTipText("Save Level");
    barSaveLevel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionSaveLevel();
        }
    });
    barSaveLevel.setIcon(
            new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_save_level.png")));
    toolBar.add(barSaveLevel);

    toolBar.addSeparator();

    barViewItems = new JToggleButton("");
    barViewItems.setToolTipText("Toggle View Items");
    barViewItems.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionToggle(true);
        }
    });

    barViewSpawn = new JToggleButton("");
    barViewSpawn.setToolTipText("Toggle View Spawn");
    barViewSpawn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionToggle(true);
        }
    });

    barClearLevel = new JButton("");
    barClearLevel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionClearLevel();
        }
    });
    barClearLevel.setToolTipText("Clear Level");
    barClearLevel.setIcon(
            new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_clear_level.png")));
    toolBar.add(barClearLevel);

    toolBar.addSeparator();

    barViewSpawn.setSelected(true);
    barViewSpawn.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_spawn.png")));
    toolBar.add(barViewSpawn);
    barViewItems.setSelected(true);
    barViewItems.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_items.png")));
    toolBar.add(barViewItems);

    barViewDoorItems = new JToggleButton("");
    barViewDoorItems.setToolTipText("Toggle View Door Items");
    barViewDoorItems.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionToggle(true);
        }
    });
    barViewDoorItems.setSelected(true);
    barViewDoorItems.setIcon(
            new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_door_items.png")));
    toolBar.add(barViewDoorItems);

    barViewEnemies = new JToggleButton("");
    barViewEnemies.setToolTipText("toggle View Enemies");
    barViewEnemies.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionToggle(true);
        }
    });
    barViewEnemies.setSelected(true);
    barViewEnemies
            .setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_enemies.png")));
    toolBar.add(barViewEnemies);

    barViewTypes = new JToggleButton("");
    barViewTypes.setToolTipText("Toggle view Combo Help");
    barViewTypes.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionToggle(true);
        }
    });
    barViewTypes.setSelected(true);
    barViewTypes.setIcon(
            new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_combo_infos.png")));
    toolBar.add(barViewTypes);

    barViewSpawn.setSelected(config.getBoolean("Hazelnutt.gui.viewSpawn", true));
    barViewItems.setSelected(config.getBoolean("Hazelnutt.gui.viewItems", true));
    barViewDoorItems.setSelected(config.getBoolean("Hazelnutt.gui.viewDoorItems", true));
    barViewEnemies.setSelected(config.getBoolean("Hazelnutt.gui.viewEnemies", true));
    barViewTypes.setSelected(config.getBoolean("Hazelnutt.gui.viewHelp", true));

    panel = new JPanel();
    contentPane.add(panel, BorderLayout.EAST);
    panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

    selectorPanel = new SelectorPanel();
    selectorPanel.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"),
            "Combo & Entity Selector", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 70, 213)));
    panel.add(selectorPanel);

    propertiesPanel = new PropertiesPanel(null);
    propertiesPanel.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Level Properties",
            TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 70, 213)));
    panel.add(propertiesPanel);

    toolBar.addSeparator();

    scaleButton = new JToggleButton("");
    scaleButton.setToolTipText("Toggle Scale Display");
    scaleButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionScale(true);
        }
    });
    scaleButton.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_x2.png")));
    toolBar.add(scaleButton);

    scaleButton.setSelected(config.getBoolean("Hazelnutt.gui.scaled", false));

    gridButton = new JToggleButton("");
    gridButton.setToolTipText("Display Grid");
    gridButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            actionGrid(true);
        }
    });
    gridButton.setIcon(new ImageIcon(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/icon_grid.png")));
    toolBar.add(gridButton);

    gridButton.setSelected(config.getBoolean("Hazelnutt.gui.grid", false));

    Component horizontalGlue = Box.createHorizontalGlue();
    toolBar.add(horizontalGlue);

    Component verticalGlue = Box.createVerticalGlue();
    panel.add(verticalGlue);

    levelWrapper = new JPanel();
    levelWrapper.setBorder(new TitledBorder(UIManager.getBorder("TitledBorder.border"), "Level",
            TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 70, 213)));
    contentPane.add(levelWrapper, BorderLayout.CENTER);
    levelWrapper.setLayout(new BorderLayout(0, 0));

    scrollPane = new JScrollPane();
    scrollPane.setBorder(new EmptyBorder(0, 0, 0, 0));
    levelWrapper.add(scrollPane);

    levelDisplay = new LevelDisplay();
    levelDisplay.addEditListener(new EditListener() {
        @Override
        public void leftPressed(int x, int y) {
            SelectionType st = selectorPanel.getSelectionType();
            Object so = selectorPanel.getSelectedObject();

            if (st == SelectionType.COMBO) {
                paintComboAt(x, y, ((Byte) so).byteValue());
            } else if (st == SelectionType.SPAWN) {
                selectedLevel.getRomLevel().setSpawn(new IntVector(x, y));

                levelHasChanged = true;
            } else if (st == SelectionType.ITEM) {
                Item ent = new Item((ItemType) so, x, y);
                EntityCollection<Item> ents = selectedLevel.getRomLevel().getItems();
                for (Iterator<Item> it = ents.iterator(); it.hasNext();) {
                    Item item = it.next();
                    if (item.getX() == x && item.getY() == y) {
                        it.remove();
                    }
                }
                if (ents.size() <= ents.maxSize()) {
                    ents.add(ent);
                    levelHasChanged = true;
                }
            } else if (st == SelectionType.DOOR_ITEM) {
                Item ent = new Item((ItemType) so, x, y);
                EntityCollection<Item> ents = selectedLevel.getRomLevel().getDoorItems();
                for (Iterator<Item> it = ents.iterator(); it.hasNext();) {
                    Item item = it.next();
                    if (item.getX() == x && item.getY() == y) {
                        it.remove();
                    }
                }
                if (ents.size() <= ents.maxSize()) {
                    ents.add(ent);
                    levelHasChanged = true;
                }
            } else if (st == SelectionType.ENEMY) {
                Enemy ent = new Enemy((EnemyType) so, x, y);
                EntityCollection<Enemy> ents = selectedLevel.getRomLevel().getEnemies();
                for (Iterator<Enemy> it = ents.iterator(); it.hasNext();) {
                    Enemy enem = it.next();
                    if (enem.getX() == x && enem.getY() == y) {
                        it.remove();
                    }
                }
                if (ents.size() <= ents.maxSize()) {
                    ents.add(ent);
                    levelHasChanged = true;
                }
            }

            updateTitle();
            levelDisplay.repaint();
            levelHasChanged = true;
        }

        @Override
        public void centerPressed(int x, int y) {
            selectorPanel.forceComboSelection(selectedLevel.getRomLevel().getData()[x][y]);
        }

        @Override
        public void rightPressed(int x, int y) {
            deleteVisibleEntitiesAt(x, y);
        }

        @Override
        public void leftDragged(int x, int y) {
            if (selectorPanel.getSelectionType() == SelectionType.COMBO) {
                paintComboAt(x, y, ((Byte) selectorPanel.getSelectedObject()).byteValue());
            }
        }

        @Override
        public void centerDragged(int x, int y) {
            // Nothing to de here
        }

        @Override
        public void rightDragged(int x, int y) {
            deleteVisibleEntitiesAt(x, y);
        }

        // Utility methods
        /*private void selectComboAt ( int x, int y ) {
                   
        }/**/
        private void paintComboAt(int x, int y, byte value) {
            selectedLevel.getRomLevel().getData()[x][y] = value;
            levelHasChanged = true;

            updateTitle();
            levelDisplay.repaint();
        }

        private void deleteVisibleEntitiesAt(int x, int y) {
            Collection<Item> items = selectedLevel.getRomLevel().getItems();
            Collection<Item> doorItems = selectedLevel.getRomLevel().getDoorItems();
            Collection<Enemy> enemies = selectedLevel.getRomLevel().getEnemies();

            if (barViewItems.isSelected()) {
                for (Iterator<Item> it = items.iterator(); it.hasNext();) {
                    Item item = it.next();
                    if (item.getX() == x && item.getY() == y) {
                        it.remove();
                        levelHasChanged = true;
                    }
                }
            }

            if (barViewDoorItems.isSelected()) {
                for (Iterator<Item> it = doorItems.iterator(); it.hasNext();) {
                    Item doorItem = it.next();
                    if (doorItem.getX() == x && doorItem.getY() == y) {
                        it.remove();
                        levelHasChanged = true;
                    }
                }
            }

            if (barViewEnemies.isSelected()) {
                for (Iterator<Enemy> it = enemies.iterator(); it.hasNext();) {
                    Enemy enem = it.next();
                    if (enem.getX() == x && enem.getY() == y) {
                        it.remove();
                        levelHasChanged = true;
                    }
                }
            }

            updateTitle();
            levelDisplay.repaint();
        }
    });
    scrollPane.setViewportView(levelDisplay);

    updateTitle();
    actionToggle(true);
    actionScale(true);
    actionGrid(true);
    setIconImage(Toolkit.getDefaultToolkit()
            .getImage(EditorFrame.class.getResource("/es/darkhogg/hazelnutt/witch_hazel_big.png")));
    setRomFeaturesEnabled(false);
    setLevelFeaturesEnabled(false);

    if (config.getBoolean("Hazelnutt.gui.maximum", false)) {
        setExtendedState(getExtendedState() | JFrame.MAXIMIZED_BOTH);
    } else {
        int x = config.getInt("Hazelnutt.gui.location.x", Integer.MIN_VALUE);
        int y = config.getInt("Hazelnutt.gui.location.y", Integer.MIN_VALUE);
        int w = config.getInt("Hazelnutt.gui.size.width", Integer.MIN_VALUE);
        int h = config.getInt("Hazelnutt.gui.size.height", Integer.MIN_VALUE);

        if (x == Integer.MIN_VALUE || x == Integer.MIN_VALUE || w == Integer.MIN_VALUE
                || h == Integer.MIN_VALUE) {
            setLocationRelativeTo(null);
        } else {
            setLocation(x, y);
            setSize(w, h);
        }
    }

    propertiesPanel.addApplyListener(new PropertiesPanel.ApplyListener() {
        @Override
        public void apply() {
            levelHasChanged = true;
            updateTitle();
            updateDisplay();
        }
    });

    if (config.containsKey("Hazelnutt.gui.lastDirectory")) {
        File lastDir = new File(config.getString("Hazelnutt.gui.lastDirectory"));
        if (lastDir.exists() && lastDir.isDirectory()) {
            //logger.debug( "Resetting the last directory: '" + lastDir + "'" );
            fileChooser.setCurrentDirectory(lastDir);
        }
    }

    // Configure the PgUp and PgDn shortcuts
    InputMap im = contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    im.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, 0), "PgUp");
    im.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0), "PgDn");
    ActionMap am = contentPane.getActionMap();
    am.put("PgUp", new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            actionLevelUp();
        }
    });
    am.put("PgDn", new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            actionLevelDown();
        }
    });

    // Get the recent files
    recentFiles = new LinkedList<String>(Arrays.asList(config.getStringArray("Hazelnutt.gui.recentFiles")));
    updateRecentFiles();

}

From source file:br.com.atmatech.sac.view.ViewAtendimento.java

private void inicializaAtalhos() {
    KeyStroke keyStrokeJBalterar = KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0);
    String actionNameJBalterar = "TECLA_F2";
    InputMap inputMapJBalterar = jBalterar.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);

    inputMapJBalterar.put(keyStrokeJBalterar, actionNameJBalterar);
    ActionMap actionMapJBMARCA = jBalterar.getActionMap();
    actionMapJBMARCA.put(actionNameJBalterar, acaojBnovo);

    //Atalho excluir
    KeyStroke keyStrokeJBexcluir = KeyStroke.getKeyStroke(KeyEvent.VK_F4, 0);
    String actionNameJBexcluir = "F4";
    InputMap inputMapJBexcluir = jBexcluir.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);

    inputMapJBexcluir.put(keyStrokeJBexcluir, actionNameJBexcluir);
    ActionMap actionMapJBexcluir = jBexcluir.getActionMap();
    actionMapJBexcluir.put(actionNameJBexcluir, acaoJBexcluir);

    //aTALHO AJUDA
    KeyStroke keyStrokeJBajuda = KeyStroke.getKeyStroke(KeyEvent.VK_F9, 0);
    String actionNameJBajuda = "TECLA_F9";
    InputMap inputMapJBajuda = jBajuda.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);

    inputMapJBajuda.put(keyStrokeJBajuda, actionNameJBajuda);
    ActionMap actionMapJBajuda = jBajuda.getActionMap();
    actionMapJBajuda.put(actionNameJBajuda, acaoJBajuda);

    //Atalho enter
    InputMap inputMapJBenter = this.jDcombocliente.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    inputMapJBenter.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "forward");
    this.jDcombocliente.getRootPane().setInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW, inputMapJBenter);
    this.jDcombocliente.getRootPane().getActionMap().put("forward", new AbstractAction() {
        private static final long serialVersionUID = 1L;

        @Override//from w w  w.j  ava 2s.  c  om
        public void actionPerformed(ActionEvent e) {
            selecionaCliente();
        }

    });
}

From source file:edu.ku.brc.ui.UIHelper.java

/**
 * Helper for adding KeyBindings./*w w  w  . j  a  va2  s  . c om*/
 * @param comp the component (usually a JButton)
 * @param action the action to be invoked
 * @param actionName the name to put into the map for the action
 * @param keyCode the key code
 * @param modifier the modifer
 */
public static void addKeyBinding(final JComponent comp, final Action action, final String actionName,
        final int keyCode, final int modifier) {
    KeyStroke ctrlS = KeyStroke.getKeyStroke(keyCode, modifier);
    InputMap inputMap = comp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);

    inputMap.put(ctrlS, actionName);
    ActionMap actionMap = comp.getActionMap();
    actionMap.put(actionName, action);
}

From source file:com.haulmont.cuba.desktop.sys.DesktopWindowManager.java

protected void assignDialogShortcuts(final JDialog dialog, JPanel panel, final Action[] actions) {
    ClientConfig clientConfig = configuration.getConfig(ClientConfig.class);

    InputMap inputMap = panel.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    ActionMap actionMap = panel.getActionMap();

    String commitShortcut = getConfigValueIfConnected(clientConfig::getCommitShortcut,
            "cuba.gui.commitShortcut", "CTRL-ENTER");

    KeyCombination okCombination = KeyCombination.create(commitShortcut);
    KeyStroke okKeyStroke = DesktopComponentsHelper.convertKeyCombination(okCombination);

    inputMap.put(okKeyStroke, "okAction");
    actionMap.put("okAction", new javax.swing.AbstractAction() {
        @Override/*from w  w w .  j  ava2s. c  o  m*/
        public void actionPerformed(ActionEvent e) {
            for (Action action : actions) {
                if (action instanceof DialogAction) {
                    switch (((DialogAction) action).getType()) {
                    case OK:
                    case YES:
                        action.actionPerform(null);
                        dialog.setVisible(false);
                        cleanupAfterModalDialogClosed(null);
                        return;
                    }
                }
            }
        }
    });

    String closeShortcut = getConfigValueIfConnected(clientConfig::getCloseShortcut, "cuba.gui.closeShortcut",
            "ESCAPE");

    KeyCombination closeCombination = KeyCombination.create(closeShortcut);
    KeyStroke closeKeyStroke = DesktopComponentsHelper.convertKeyCombination(closeCombination);

    inputMap.put(closeKeyStroke, "closeAction");
    actionMap.put("closeAction", new javax.swing.AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (actions.length == 1) {
                actions[0].actionPerform(null);
                dialog.setVisible(false);
                cleanupAfterModalDialogClosed(null);
            } else {
                for (Action action : actions) {
                    if (action instanceof DialogAction) {
                        switch (((DialogAction) action).getType()) {
                        case CANCEL:
                        case CLOSE:
                        case NO:
                            action.actionPerform(null);
                            dialog.setVisible(false);
                            cleanupAfterModalDialogClosed(null);
                            return;
                        }
                    }
                }
            }
        }
    });
}

From source file:net.java.sip.communicator.impl.gui.main.chat.ChatPanel.java

/**
 * Sets the chat session to associate to this chat panel.
 * @param chatSession the chat session to associate to this chat panel
 *///from w  ww .  j  a  v a  2 s  .c  o  m
public void setChatSession(ChatSession chatSession) {
    if (this.chatSession != null) {
        // remove old listener
        this.chatSession.removeChatTransportChangeListener(this);
    }

    this.chatSession = chatSession;
    this.chatSession.addChatTransportChangeListener(this);

    if ((this.chatSession != null) && this.chatSession.isContactListSupported()) {
        topPanel.remove(conversationPanelContainer);

        TransparentPanel rightPanel = new TransparentPanel(new BorderLayout());
        Dimension chatConferencesListsPanelSize = new Dimension(150, 25);
        Dimension chatContactsListsPanelSize = new Dimension(150, 175);
        Dimension rightPanelSize = new Dimension(150, 200);
        rightPanel.setMinimumSize(rightPanelSize);
        rightPanel.setPreferredSize(rightPanelSize);

        TransparentPanel contactsPanel = new TransparentPanel(new BorderLayout());
        contactsPanel.setMinimumSize(chatContactsListsPanelSize);
        contactsPanel.setPreferredSize(chatContactsListsPanelSize);

        conferencePanel.setMinimumSize(chatConferencesListsPanelSize);
        conferencePanel.setPreferredSize(chatConferencesListsPanelSize);

        this.chatContactListPanel = new ChatRoomMemberListPanel(this);
        this.chatContactListPanel.setOpaque(false);

        topSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
        topSplitPane.setBorder(null); // remove default borders
        topSplitPane.setOneTouchExpandable(true);
        topSplitPane.setOpaque(false);
        topSplitPane.setResizeWeight(1.0D);

        Color msgNameBackground = Color.decode(ChatHtmlUtils.MSG_NAME_BACKGROUND);

        // add border to the divider
        if (topSplitPane.getUI() instanceof BasicSplitPaneUI) {
            ((BasicSplitPaneUI) topSplitPane.getUI()).getDivider()
                    .setBorder(BorderFactory.createLineBorder(msgNameBackground));
        }

        ChatTransport chatTransport = chatSession.getCurrentChatTransport();

        JPanel localUserLabelPanel = new JPanel(new BorderLayout());
        JLabel localUserLabel = new JLabel(chatTransport.getProtocolProvider().getAccountID().getDisplayName());

        localUserLabel.setFont(localUserLabel.getFont().deriveFont(Font.BOLD));
        localUserLabel.setHorizontalAlignment(SwingConstants.CENTER);
        localUserLabel.setBorder(BorderFactory.createEmptyBorder(2, 0, 3, 0));
        localUserLabel.setForeground(Color.decode(ChatHtmlUtils.MSG_IN_NAME_FOREGROUND));

        localUserLabelPanel.add(localUserLabel, BorderLayout.CENTER);
        localUserLabelPanel.setBackground(msgNameBackground);

        JButton joinConference = new JButton(
                GuiActivator.getResources().getI18NString("service.gui.JOIN_VIDEO"));

        joinConference.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                showChatConferenceDialog();
            }
        });
        contactsPanel.add(localUserLabelPanel, BorderLayout.NORTH);
        contactsPanel.add(chatContactListPanel, BorderLayout.CENTER);

        conferencePanel.add(joinConference, BorderLayout.CENTER);

        rightPanel.add(conferencePanel, BorderLayout.NORTH);
        rightPanel.add(contactsPanel, BorderLayout.CENTER);

        topSplitPane.setLeftComponent(conversationPanelContainer);
        topSplitPane.setRightComponent(rightPanel);

        topPanel.add(topSplitPane);

    } else {
        if (topSplitPane != null) {
            if (chatContactListPanel != null) {
                topSplitPane.remove(chatContactListPanel);
                chatContactListPanel = null;
            }

            this.messagePane.remove(topSplitPane);
            topSplitPane = null;
        }

        topPanel.add(conversationPanelContainer);
    }

    if (chatSession instanceof MetaContactChatSession) {
        // The subject panel is added here, because it's specific for the
        // multi user chat and is not contained in the single chat chat panel.
        if (subjectPanel != null) {
            this.remove(subjectPanel);
            subjectPanel = null;

            this.revalidate();
            this.repaint();
        }

        writeMessagePanel.initPluginComponents();
        writeMessagePanel.setTransportSelectorBoxVisible(true);

        //Enables to change the protocol provider by simply pressing the
        // CTRL-P key combination
        ActionMap amap = this.getActionMap();

        amap.put("ChangeProtocol", new ChangeTransportAction());

        InputMap imap = this.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);

        imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_P, KeyEvent.CTRL_DOWN_MASK), "ChangeProtocol");
    } else if (chatSession instanceof ConferenceChatSession) {
        ConferenceChatSession confSession = (ConferenceChatSession) chatSession;

        writeMessagePanel.setTransportSelectorBoxVisible(false);

        confSession.addLocalUserRoleListener(this);
        confSession.addMemberRoleListener(this);

        ChatRoom room = ((ChatRoomWrapper) chatSession.getDescriptor()).getChatRoom();
        room.addMemberPropertyChangeListener(this);

        setConferencesPanelVisible(room.getCachedConferenceDescriptionSize() > 0);
        subjectPanel = new ChatRoomSubjectPanel((ConferenceChatSession) chatSession);

        // The subject panel is added here, because it's specific for the
        // multi user chat and is not contained in the single chat chat panel.
        this.add(subjectPanel, BorderLayout.NORTH);

        this.revalidate();
        this.repaint();
    }

    if (chatContactListPanel != null) {
        // Initialize chat participants' panel.
        Iterator<ChatContact<?>> chatParticipants = chatSession.getParticipants();

        while (chatParticipants.hasNext())
            chatContactListPanel.addContact(chatParticipants.next());
    }
}

From source file:edu.ku.brc.specify.tasks.subpane.qb.QueryBldrPane.java

/**
 * create the query builder UI.//  www  .  j  a va 2s. c  o  m
 */
protected void createUI() {
    removeAll();

    JMenuItem saveItem = new JMenuItem(UIRegistry.getResourceString("QB_SAVE"));
    Action saveActionListener = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            if (saveQuery(false)) {
                try {
                    String selId = null;
                    if (selectedQFP != null && selectedQFP.getQueryField() != null) {
                        selId = selectedQFP.getQueryField().getStringId();
                    }
                    final String selectedFldId = selId;
                    setupUI(true);
                    SwingUtilities.invokeLater(new Runnable() {

                        /* (non-Javadoc)
                         * @see java.lang.Runnable#run()
                         */
                        @Override
                        public void run() {
                            if (selectedFldId != null) {
                                for (QueryFieldPanel qfp : queryFieldItems) {
                                    if (qfp.getQueryField() != null
                                            && selectedFldId.equals(qfp.getQueryField().getStringId())) {
                                        selectQFP(qfp);
                                        return;
                                    }
                                }
                                selectQFP(queryFieldItems.get(0));
                            }
                        }

                    });
                } catch (Exception ex) {

                }
                setSaveBtnEnabled(false);
            }
        }
    };
    saveItem.addActionListener(saveActionListener);

    JMenuItem saveAsItem = new JMenuItem(UIRegistry.getResourceString("QB_SAVE_AS"));
    Action saveAsActionListener = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            if (saveQuery(true)) {
                setSaveBtnEnabled(false);
            }
        }
    };
    saveAsItem.addActionListener(saveAsActionListener);
    JComponent[] itemSample = { saveItem, saveAsItem };
    saveBtn = new DropDownButton(UIRegistry.getResourceString("QB_SAVE"), null, 1,
            java.util.Arrays.asList(itemSample));
    saveBtn.addActionListener(saveActionListener);
    String ACTION_KEY = "SAVE";
    KeyStroke ctrlS = KeyStroke.getKeyStroke(KeyEvent.VK_S,
            Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
    InputMap inputMap = saveBtn.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    inputMap.put(ctrlS, ACTION_KEY);
    ActionMap actionMap = saveBtn.getActionMap();
    actionMap.put(ACTION_KEY, saveActionListener);
    ACTION_KEY = "SAVE_AS";
    KeyStroke ctrlA = KeyStroke.getKeyStroke(KeyEvent.VK_A,
            Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
    inputMap.put(ctrlA, ACTION_KEY);
    actionMap.put(ACTION_KEY, saveAsActionListener);
    saveBtn.setActionMap(actionMap);

    UIHelper.setControlSize(saveBtn);
    //saveBtn.setOverrideBorder(true, BasicBorders.getButtonBorder());

    listBoxPanel = new JPanel(new HorzLayoutManager(2, 2));

    Vector<TableQRI> list = new Vector<TableQRI>();
    for (int k = 0; k < tableTree.getKids(); k++) {
        list.add(tableTree.getKid(k).getTableQRI());
    }

    Collections.sort(list);
    DefaultListModel model = new DefaultListModel();
    for (TableQRI qri : list) {
        model.addElement(qri);
    }

    tableList = new JList(model);
    QryListRenderer qr = new QryListRenderer(IconManager.IconSize.Std16);
    qr.setDisplayKidIndicator(false);
    tableList.setCellRenderer(qr);

    JScrollPane spt = new JScrollPane(tableList, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    Dimension pSize = spt.getPreferredSize();
    pSize.height = 200;
    spt.setPreferredSize(pSize);

    JPanel topPanel = new JPanel(new BorderLayout());

    scrollPane = new JScrollPane(listBoxPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);

    tableList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                int inx = tableList.getSelectedIndex();
                if (inx > -1) {
                    fillNextList(tableList);
                } else {
                    listBoxPanel.removeAll();
                }
            }
        }
    });

    addBtn = new JButton(IconManager.getImage("PlusSign", IconManager.IconSize.Std16));
    addBtn.setEnabled(false);
    addBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            BaseQRI qri = (BaseQRI) listBoxList.get(currentInx).getSelectedValue();
            if (qri.isInUse) {
                return;
            }

            try {
                FieldQRI fieldQRI = buildFieldQRI(qri);
                if (fieldQRI == null) {
                    throw new Exception("null FieldQRI");
                }
                SpQueryField qf = new SpQueryField();
                qf.initialize();
                qf.setFieldName(fieldQRI.getFieldName());
                qf.setStringId(fieldQRI.getStringId());
                query.addReference(qf, "fields");

                if (!isExportMapping) {
                    addQueryFieldItem(fieldQRI, qf, false);
                } else {
                    addNewMapping(fieldQRI, qf, null, false);
                }
            } catch (Exception ex) {
                log.error(ex);
                UsageTracker.incrHandledUsageCount();
                edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(QueryBldrPane.class, ex);
                return;
            }
        }
    });

    contextPanel = new JPanel(new BorderLayout());
    contextPanel.add(createLabel("Search Context", SwingConstants.CENTER), BorderLayout.NORTH); // I18N
    contextPanel.add(spt, BorderLayout.CENTER);
    contextPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10));

    JPanel schemaPanel = new JPanel(new BorderLayout());
    schemaPanel.add(scrollPane, BorderLayout.CENTER);

    topPanel.add(contextPanel, BorderLayout.WEST);
    topPanel.add(schemaPanel, BorderLayout.CENTER);
    add(topPanel, BorderLayout.NORTH);

    queryFieldsPanel = new JPanel();
    queryFieldsPanel.setLayout(new NavBoxLayoutManager(0, 2));
    queryFieldsScroll = new JScrollPane(queryFieldsPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    queryFieldsScroll.setBorder(null);
    add(queryFieldsScroll);

    //if (!isExportMapping)
    //{
    final JPanel mover = buildMoverPanel(false);
    add(mover, BorderLayout.EAST);
    // }

    String searchLbl = schemaMapping == null ? getResourceString("QB_SEARCH")
            : getResourceString("QB_EXPORT_PREVIEW");
    searchBtn = createButton(searchLbl);
    searchBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            //               int m = ae.getModifiers();
            //               boolean ors = (m & ActionEvent.ALT_MASK) > 0 && (m & ActionEvent.CTRL_MASK) > 0 && (m & ActionEvent.SHIFT_MASK) > 0;
            //               if (ors)
            //               {
            //                  System.out.println("Disjunctional conjoinment desire gesture detected");
            //               }
            //               doSearch(ors);
            doSearch(false);
        }
    });
    distinctChk = createCheckBox(UIRegistry.getResourceString("QB_DISTINCT"));
    distinctChk.setVisible(schemaMapping == null);
    if (schemaMapping == null) {
        distinctChk.setSelected(false);
        distinctChk.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                new SwingWorker() {

                    /* (non-Javadoc)
                     * @see edu.ku.brc.helpers.SwingWorker#construct()
                     */
                    @Override
                    public Object construct() {
                        if (distinctChk.isSelected()) {
                            UsageTracker.incrUsageCount("QB.DistinctOn");
                        } else {
                            UsageTracker.incrUsageCount("QB.DistinctOff");
                        }
                        if ((isTreeLevelSelected() || isAggFieldSelected()) && countOnly
                                && distinctChk.isSelected()) {
                            countOnlyChk.setSelected(false);
                            countOnly = false;
                        }
                        query.setCountOnly(countOnly);
                        query.setSelectDistinct(distinctChk.isSelected());
                        setSaveBtnEnabled(thereAreItems());
                        return null;
                    }
                }.start();
            }
        });
    }
    countOnlyChk = createCheckBox(UIRegistry.getResourceString("QB_COUNT_ONLY"));
    countOnlyChk.setSelected(false);
    countOnlyChk.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            new SwingWorker() {

                /* (non-Javadoc)
                 * @see edu.ku.brc.helpers.SwingWorker#construct()
                 */
                @Override
                public Object construct() {
                    //Don't allow change while query is running.
                    if (runningResults.get() == null) {
                        countOnly = !countOnly;
                        if (countOnly) {
                            UsageTracker.incrUsageCount("QB.CountOnlyOn");
                        } else {
                            UsageTracker.incrUsageCount("QB.CountOnlyOff");
                        }
                        if ((isTreeLevelSelected() || isAggFieldSelected()) && countOnly
                                && (distinctChk.isSelected() || searchSynonymyChk.isSelected())) {
                            distinctChk.setSelected(false);
                            searchSynonymyChk.setSelected(false);
                        }
                    } else {
                        //This might be awkward and/or klunky...
                        countOnlyChk.setSelected(countOnly);
                    }
                    query.setCountOnly(countOnly);
                    query.setSelectDistinct(distinctChk.isSelected());
                    setSaveBtnEnabled(thereAreItems());
                    return null;
                }
            }.start();
        }
    });

    searchSynonymyChk = createCheckBox(UIRegistry.getResourceString("QB_SRCH_SYNONYMS"));
    searchSynonymyChk.setSelected(searchSynonymy);
    searchSynonymyChk.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            new SwingWorker() {

                /* (non-Javadoc)
                 * @see edu.ku.brc.helpers.SwingWorker#construct()
                 */
                @Override
                public Object construct() {
                    searchSynonymy = !searchSynonymy;
                    if (!searchSynonymy) {
                        UsageTracker.incrUsageCount("QB.SearchSynonymyOff");
                    } else {
                        UsageTracker.incrUsageCount("QB.SearchSynonymyOn");
                    }
                    if (isTreeLevelSelected() && countOnly && searchSynonymyChk.isSelected()) {
                        countOnlyChk.setSelected(false);
                        countOnly = false;
                    }
                    query.setSearchSynonymy(searchSynonymy);
                    setSaveBtnEnabled(thereAreItems());
                    return null;
                }
            }.start();
        }
    });

    smushedChk = createCheckBox(UIRegistry.getResourceString("QB_SMUSH_RESULTS"));
    smushedChk.setVisible(isSmushableContext());
    if (isSmushableContext()) {
        smushedChk.setSelected(smushed);
        smushedChk.setToolTipText(
                String.format(UIRegistry.getResourceString("QB_SMUSH_RESULTS_HINT"), getCatalogNumberTitle()));
        smushedChk.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                new SwingWorker() {

                    /*
                     * (non-Javadoc)
                     * 
                     * @see edu.ku.brc.helpers.SwingWorker#construct()
                     */
                    @Override
                    public Object construct() {
                        smushed = !smushed;
                        if (!smushed) {
                            UsageTracker.incrUsageCount("QB.SmushedOff");
                        } else {
                            UsageTracker.incrUsageCount("QB.SmushedOn");
                        }
                        query.setSmushed(smushed);
                        setSaveBtnEnabled(thereAreItems());
                        return null;
                    }
                }.start();
            }
        });
    }

    PanelBuilder outer = new PanelBuilder(
            new FormLayout("p, 2dlu, p, 2dlu, p, 2dlu, p, 2dlu, p, 6dlu, p", "p"));

    CellConstraints cc = new CellConstraints();
    outer.add(smushedChk, cc.xy(1, 1));
    outer.add(searchSynonymyChk, cc.xy(3, 1));
    outer.add(distinctChk, cc.xy(5, 1));
    outer.add(countOnlyChk, cc.xy(7, 1));
    outer.add(searchBtn, cc.xy(9, 1));
    outer.add(saveBtn, cc.xy(11, 1));

    JPanel bottom = new JPanel(new BorderLayout());
    bottom.add(outer.getPanel(), BorderLayout.EAST);

    JButton helpBtn = UIHelper.createHelpIconButton(getHelpBtnContext());
    bottom.add(helpBtn, BorderLayout.WEST);
    add(bottom, BorderLayout.SOUTH);

    setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
}

From source file:edu.ku.brc.specify.tasks.subpane.wb.WorkbenchPaneSS.java

/**
 * Adds a Key mappings.// w  ww. ja v a 2  s . com
 * @param comp comp
 * @param keyCode keyCode
 * @param actionName actionName
 * @param action action 
 * @return the action
 */
public Action addRecordKeyMappings(final JComponent comp, final int keyCode, final String actionName,
        final Action action, int modifiers) {
    InputMap inputMap = comp.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    ActionMap actionMap = comp.getActionMap();

    inputMap.put(KeyStroke.getKeyStroke(keyCode, modifiers), actionName);
    actionMap.put(actionName, action);

    //UIRegistry.registerAction(actionName, action);
    return action;
}

From source file:net.sourceforge.pmd.util.designer.Designer.java

private static void makeTextComponentUndoable(JTextComponent textConponent) {
    final UndoManager undoManager = new UndoManager();
    textConponent.getDocument().addUndoableEditListener(new UndoableEditListener() {
        @Override//www.  j a va2s  .  c  o  m
        public void undoableEditHappened(UndoableEditEvent evt) {
            undoManager.addEdit(evt.getEdit());
        }
    });
    ActionMap actionMap = textConponent.getActionMap();
    InputMap inputMap = textConponent.getInputMap();
    actionMap.put("Undo", new AbstractAction("Undo") {
        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                if (undoManager.canUndo()) {
                    undoManager.undo();
                }
            } catch (CannotUndoException e) {
                throw new RuntimeException(e);
            }
        }
    });
    inputMap.put(KeyStroke.getKeyStroke("control Z"), "Undo");

    actionMap.put("Redo", new AbstractAction("Redo") {
        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                if (undoManager.canRedo()) {
                    undoManager.redo();
                }
            } catch (CannotRedoException e) {
                throw new RuntimeException(e);
            }
        }
    });
    inputMap.put(KeyStroke.getKeyStroke("control Y"), "Redo");
}

From source file:org.apache.jmeter.gui.action.SearchTreeDialog.java

@Override
protected JRootPane createRootPane() {
    JRootPane rootPane = new JRootPane();
    // Hide Window on ESC
    Action escapeAction = new AbstractAction("ESCAPE") {

        private static final long serialVersionUID = -6543764044868772971L;

        @Override/*from w ww.  ja v a 2 s  .co m*/
        public void actionPerformed(ActionEvent actionEvent) {
            setVisible(false);
        }
    };
    // Do search on Enter
    Action enterAction = new AbstractAction("ENTER") {

        private static final long serialVersionUID = -3661361497864527363L;

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            doSearch(actionEvent);
        }
    };
    ActionMap actionMap = rootPane.getActionMap();
    actionMap.put(escapeAction.getValue(Action.NAME), escapeAction);
    actionMap.put(enterAction.getValue(Action.NAME), enterAction);
    InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    inputMap.put(KeyStrokes.ESC, escapeAction.getValue(Action.NAME));
    inputMap.put(KeyStrokes.ENTER, enterAction.getValue(Action.NAME));

    return rootPane;
}

From source file:org.docx4all.swing.text.WordMLEditorKit.java

private void initKeyBindings(JEditorPane editor) {
    ActionMap myActionMap = new ActionMap();
    InputMap myInputMap = new InputMap();

    KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, InputEvent.SHIFT_MASK);
    myActionMap.put(insertSoftBreakAction, new InsertSoftBreakAction(insertSoftBreakAction));
    myInputMap.put(ks, insertSoftBreakAction);

    ks = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
    myActionMap.put(enterKeyTypedAction, new EnterKeyTypedAction(enterKeyTypedAction));
    myInputMap.put(ks, enterKeyTypedAction);

    ks = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0);
    myActionMap.put(deleteNextCharAction, new DeleteNextCharAction(deleteNextCharAction));
    myInputMap.put(ks, deleteNextCharAction);

    ks = KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0);
    myActionMap.put(deletePrevCharAction, new DeletePrevCharAction(deletePrevCharAction));
    myInputMap.put(ks, deletePrevCharAction);

    myActionMap.setParent(editor.getActionMap());
    myInputMap.setParent(editor.getInputMap());
    editor.setActionMap(myActionMap);/* w w  w.  j a  v a2 s .  com*/
    editor.setInputMap(JComponent.WHEN_FOCUSED, myInputMap);
}