Example usage for java.awt.event InputEvent SHIFT_MASK

List of usage examples for java.awt.event InputEvent SHIFT_MASK

Introduction

In this page you can find the example usage for java.awt.event InputEvent SHIFT_MASK.

Prototype

int SHIFT_MASK

To view the source code for java.awt.event InputEvent SHIFT_MASK.

Click Source Link

Document

The Shift key modifier constant.

Usage

From source file:com.igormaznitsa.jhexed.swing.editor.ui.MainForm.java

/**
 * This method is called from within the constructor to initialize the form.
 * WARNING: Do NOT modify this code. The content of this method is always
 * regenerated by the Form Editor.// www  .ja va2 s.  com
 */
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {

    panelMainArea = new javax.swing.JPanel();
    jPanel1 = new javax.swing.JPanel();
    labelCellUnderMouse = new javax.swing.JLabel();
    labelZoomStatus = new javax.swing.JLabel();
    menuMain = new javax.swing.JMenuBar();
    menuFile = new javax.swing.JMenu();
    menuFileNew = new javax.swing.JMenuItem();
    menuItemFileOpen = new javax.swing.JMenuItem();
    menuFileSave = new javax.swing.JMenuItem();
    menuFileSaveAs = new javax.swing.JMenuItem();
    jSeparator1 = new javax.swing.JPopupMenu.Separator();
    menuFileExportAs = new javax.swing.JMenu();
    menuFileExportAsImage = new javax.swing.JMenuItem();
    menuFileExportAsSVG = new javax.swing.JMenuItem();
    menuFileExportAsXML = new javax.swing.JMenuItem();
    menuFileExportAsJavaConstants = new javax.swing.JMenuItem();
    jSeparator3 = new javax.swing.JPopupMenu.Separator();
    menuFileDocumentOptions = new javax.swing.JMenuItem();
    jSeparator4 = new javax.swing.JPopupMenu.Separator();
    menuFileExit = new javax.swing.JMenuItem();
    menuEdit = new javax.swing.JMenu();
    menuEditUndo = new javax.swing.JMenuItem();
    menuEditRedo = new javax.swing.JMenuItem();
    menuView = new javax.swing.JMenu();
    menuViewZoomIn = new javax.swing.JMenuItem();
    menuViewZoomOut = new javax.swing.JMenuItem();
    menuViewZoomReset = new javax.swing.JMenuItem();
    jSeparator2 = new javax.swing.JPopupMenu.Separator();
    menuViewBackImage = new javax.swing.JCheckBoxMenuItem();
    menuShowHexBorders = new javax.swing.JCheckBoxMenuItem();
    menuPlugins = new javax.swing.JMenu();
    menuWindow = new javax.swing.JMenu();
    menuWindowLayers = new javax.swing.JCheckBoxMenuItem();
    menuWindowTools = new javax.swing.JCheckBoxMenuItem();
    menuWindowOptions = new javax.swing.JCheckBoxMenuItem();
    menuLANDF = new javax.swing.JMenu();
    menuHelp = new javax.swing.JMenu();
    menuHelpAbout = new javax.swing.JMenuItem();

    setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
    setTitle("JHexed Map editor");
    setLocationByPlatform(true);
    setMinimumSize(new java.awt.Dimension(300, 300));
    addWindowListener(new java.awt.event.WindowAdapter() {
        public void windowClosed(java.awt.event.WindowEvent evt) {
            formWindowClosed(evt);
        }

        public void windowClosing(java.awt.event.WindowEvent evt) {
            formWindowClosing(evt);
        }
    });

    panelMainArea.setLayout(new java.awt.BorderLayout());

    jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

    labelCellUnderMouse.setText("   ");

    labelZoomStatus.setText("   ");

    javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(jPanel1Layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup().addContainerGap().addComponent(labelCellUnderMouse)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 705, Short.MAX_VALUE)
                    .addComponent(labelZoomStatus).addContainerGap()));
    jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
                    jPanel1Layout.createSequentialGroup().addGap(0, 0, Short.MAX_VALUE)
                            .addGroup(jPanel1Layout
                                    .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(labelCellUnderMouse).addComponent(labelZoomStatus))));

    panelMainArea.add(jPanel1, java.awt.BorderLayout.PAGE_END);

    getContentPane().add(panelMainArea, java.awt.BorderLayout.CENTER);

    menuFile.setText("File");
    menuFile.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            menuFileActionPerformed(evt);
        }
    });

    menuFileNew.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N,
            java.awt.event.InputEvent.CTRL_MASK));
    menuFileNew.setIcon(new javax.swing.ImageIcon(
            getClass().getResource("/com/igormaznitsa/jhexed/swing/editor/icons/new.png"))); // NOI18N
    menuFileNew.setText("New");
    menuFileNew.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            menuFileNewActionPerformed(evt);
        }
    });
    menuFile.add(menuFileNew);

    menuItemFileOpen.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O,
            java.awt.event.InputEvent.CTRL_MASK));
    menuItemFileOpen.setIcon(new javax.swing.ImageIcon(
            getClass().getResource("/com/igormaznitsa/jhexed/swing/editor/icons/folder-open-image.png"))); // NOI18N
    menuItemFileOpen.setText("Open");
    menuItemFileOpen.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            menuItemFileOpenActionPerformed(evt);
        }
    });
    menuFile.add(menuItemFileOpen);

    menuFileSave.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S,
            java.awt.event.InputEvent.CTRL_MASK));
    menuFileSave.setIcon(new javax.swing.ImageIcon(
            getClass().getResource("/com/igormaznitsa/jhexed/swing/editor/icons/drive-download.png"))); // NOI18N
    menuFileSave.setText("Save");
    menuFileSave.setEnabled(false);
    menuFileSave.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            menuFileSaveActionPerformed(evt);
        }
    });
    menuFile.add(menuFileSave);

    menuFileSaveAs.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S,
            java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
    menuFileSaveAs.setText("Save As...");
    menuFileSaveAs.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            menuFileSaveAsActionPerformed(evt);
        }
    });
    menuFile.add(menuFileSaveAs);
    menuFile.add(jSeparator1);

    menuFileExportAs.setText("Export as...");

    menuFileExportAsImage.setText("PNG Image");
    menuFileExportAsImage.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            menuFileExportAsImageActionPerformed(evt);
        }
    });
    menuFileExportAs.add(menuFileExportAsImage);

    menuFileExportAsSVG.setText("SVG Image");
    menuFileExportAsSVG.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            menuFileExportAsSVGActionPerformed(evt);
        }
    });
    menuFileExportAs.add(menuFileExportAsSVG);

    menuFileExportAsXML.setText("Xml file");
    menuFileExportAsXML.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            menuFileExportAsXMLActionPerformed(evt);
        }
    });
    menuFileExportAs.add(menuFileExportAsXML);

    menuFileExportAsJavaConstants.setText("Java constants");
    menuFileExportAsJavaConstants.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            menuFileExportAsJavaConstantsActionPerformed(evt);
        }
    });
    menuFileExportAs.add(menuFileExportAsJavaConstants);

    menuFile.add(menuFileExportAs);
    menuFile.add(jSeparator3);

    menuFileDocumentOptions.setText("Document options");
    menuFileDocumentOptions.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            menuFileDocumentOptionsActionPerformed(evt);
        }
    });
    menuFile.add(menuFileDocumentOptions);
    menuFile.add(jSeparator4);

    menuFileExit.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4,
            java.awt.event.InputEvent.ALT_MASK));
    menuFileExit.setIcon(new javax.swing.ImageIcon(
            getClass().getResource("/com/igormaznitsa/jhexed/swing/editor/icons/door-open-out.png"))); // NOI18N
    menuFileExit.setText("Exit");
    menuFileExit.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            menuFileExitActionPerformed(evt);
        }
    });
    menuFile.add(menuFileExit);

    menuMain.add(menuFile);

    menuEdit.setText("Edit");

    menuEditUndo.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Z,
            java.awt.event.InputEvent.CTRL_MASK));
    menuEditUndo.setText("Undo");
    menuEditUndo.setEnabled(false);
    menuEditUndo.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            menuEditUndoActionPerformed(evt);
        }
    });
    menuEdit.add(menuEditUndo);

    menuEditRedo.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X,
            java.awt.event.InputEvent.CTRL_MASK));
    menuEditRedo.setText("Redo");
    menuEditRedo.setEnabled(false);
    menuEditRedo.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            menuEditRedoActionPerformed(evt);
        }
    });
    menuEdit.add(menuEditRedo);

    menuMain.add(menuEdit);

    menuView.setText("View");

    menuViewZoomIn.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_I,
            java.awt.event.InputEvent.CTRL_MASK));
    menuViewZoomIn.setIcon(new javax.swing.ImageIcon(
            getClass().getResource("/com/igormaznitsa/jhexed/swing/editor/icons/magnifier-zoom-in.png"))); // NOI18N
    menuViewZoomIn.setText("Zoom In");
    menuViewZoomIn.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            menuViewZoomInActionPerformed(evt);
        }
    });
    menuView.add(menuViewZoomIn);

    menuViewZoomOut.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_I,
            java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
    menuViewZoomOut.setIcon(new javax.swing.ImageIcon(
            getClass().getResource("/com/igormaznitsa/jhexed/swing/editor/icons/magnifier-zoom-out.png"))); // NOI18N
    menuViewZoomOut.setText("Zoom Out");
    menuViewZoomOut.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            menuViewZoomOutActionPerformed(evt);
        }
    });
    menuView.add(menuViewZoomOut);

    menuViewZoomReset.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R,
            java.awt.event.InputEvent.CTRL_MASK));
    menuViewZoomReset.setIcon(new javax.swing.ImageIcon(
            getClass().getResource("/com/igormaznitsa/jhexed/swing/editor/icons/magnifier-zoom-actual.png"))); // NOI18N
    menuViewZoomReset.setText("Zoom Reset");
    menuViewZoomReset.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            menuViewZoomResetActionPerformed(evt);
        }
    });
    menuView.add(menuViewZoomReset);
    menuView.add(jSeparator2);

    menuViewBackImage.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_B,
            java.awt.event.InputEvent.CTRL_MASK));
    menuViewBackImage.setSelected(true);
    menuViewBackImage.setText("Show back image");
    menuViewBackImage.setToolTipText("Show/Hide the background image");
    menuViewBackImage.addChangeListener(new javax.swing.event.ChangeListener() {
        public void stateChanged(javax.swing.event.ChangeEvent evt) {
            menuViewBackImageStateChanged(evt);
        }
    });
    menuView.add(menuViewBackImage);

    menuShowHexBorders.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_H,
            java.awt.event.InputEvent.CTRL_MASK));
    menuShowHexBorders.setSelected(true);
    menuShowHexBorders.setText("Show hex borders");
    menuShowHexBorders.addChangeListener(new javax.swing.event.ChangeListener() {
        public void stateChanged(javax.swing.event.ChangeEvent evt) {
            menuShowHexBordersStateChanged(evt);
        }
    });
    menuView.add(menuShowHexBorders);

    menuMain.add(menuView);

    menuPlugins.setText("Plugins");
    menuMain.add(menuPlugins);

    menuWindow.setText("Window");

    menuWindowLayers.setSelected(true);
    menuWindowLayers.setText("Layers");
    menuWindowLayers.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            menuWindowLayersActionPerformed(evt);
        }
    });
    menuWindow.add(menuWindowLayers);

    menuWindowTools.setSelected(true);
    menuWindowTools.setText("Tools");
    menuWindowTools.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            menuWindowToolsActionPerformed(evt);
        }
    });
    menuWindow.add(menuWindowTools);

    menuWindowOptions.setSelected(true);
    menuWindowOptions.setText("Options");
    menuWindowOptions.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            menuWindowOptionsActionPerformed(evt);
        }
    });
    menuWindow.add(menuWindowOptions);

    menuMain.add(menuWindow);

    menuLANDF.setText("Look&Feel");
    menuMain.add(menuLANDF);

    menuHelp.setText("Help");

    menuHelpAbout.setText("About");
    menuHelpAbout.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            menuHelpAboutActionPerformed(evt);
        }
    });
    menuHelp.add(menuHelpAbout);

    menuMain.add(menuHelp);

    setJMenuBar(menuMain);

    pack();
}

From source file:com.jcraft.weirdx.DDXWindowImp.java

@SuppressWarnings("unused")
public void mouseDragged(MouseEvent e) {

    if (threeButton) {
        if (threeBstate != s) {
            if (threeBstate == sp) {
                procPressed(threeBPressed);
                threeBPressed = null;//from  w  w  w .ja v  a 2  s .co  m
                threeBstate = s;
            } else if (threeBstate == spp) {
                e = new MouseEvent((Component) e.getSource(), e.getID(), e.getWhen(),
                        (e.getModifiers() & (~(InputEvent.BUTTON1_MASK | InputEvent.BUTTON3_MASK)))
                                | InputEvent.BUTTON2_MASK,
                        e.getX(), e.getY(), e.getClickCount(), e.isPopupTrigger());
            } else if (threeBstate == sppr) {
                return;
            }
        }
    }

    if (window == null)
        return;

    // calc abs cursor position use old window position for calculation
    // as mouseDragged (if you use Panel) delivers its coordinates relative to the position after mousepressed
    // UPDATE: this was a bug of the IBM JDK
    //    int x=e.getX()+oldwindowx;
    //    int y=e.getY()+oldwindowy;
    int x = e.getX() + window.x;
    int y = e.getY() + window.y;

    // set new drag position (absolute)
    XWindow.sprite.hot.x = x;
    XWindow.sprite.hot.y = y;

    int mod = e.getModifiers();

    // button 1 -> 16
    // button 2 -> 8
    // button 3 -> 4
    // shift -> 1
    // control -> 2
    // alt -> 12 ?? 

    int state = 0;
    int detail = 0;

    if ((mod & InputEvent.BUTTON1_MASK) != 0) {
        state |= (1 << 8);
        detail = 1;
    }
    if ((mod & InputEvent.BUTTON2_MASK) != 0) {
        state |= (1 << 9);
        detail = 2;
    }
    if ((mod & InputEvent.BUTTON3_MASK) != 0) {
        state |= (1 << 10);
        detail = 3;
    }
    if ((mod & InputEvent.SHIFT_MASK) != 0)
        state |= 1;
    if ((mod & InputEvent.CTRL_MASK) != 0)
        state |= 4;
    // alt -> state|=8;
    XWindow.sprite.hot.state = state;

    px = x;
    py = y;

    event.mkMotionNotify(1, window.screen.rootId, XWindow.sprite.win.id, 0, px, py, e.getX(), e.getY(), state,
            1);

    try {
        if (!XWindow.checkMotion(event, window)) {
            return;
        }
        event.mkMotionNotify(1, window.screen.rootId, XWindow.sprite.win.id, 0, px, py,
                px - XWindow.sprite.win.x, py - XWindow.sprite.win.y, state, 1);
        if (XWindow.grab != null) {
            XWindow.sendGrabbedEvent(event, false, 1);
        } else {
            XWindow.sendDeviceEvent(XWindow.sprite.win, event, XWindow.grab, null, 1);
        }
    } catch (Exception ee) {
    }
}

From source file:com.jcraft.weirdx.DDXWindowImp.java

public void mouseMoved(MouseEvent e) {
    int x = e.getX() + window.x;
    int y = e.getY() + window.y;

    XWindow.sprite.hot.x = x;/* w w  w . j  a v  a 2 s.c  o m*/
    XWindow.sprite.hot.y = y;

    int mod = e.getModifiers();
    int state = 0;

    px = x;
    py = y;

    if ((mod & InputEvent.BUTTON1_MASK) != 0)
        state |= (1 << 8);
    if ((mod & InputEvent.BUTTON2_MASK) != 0)
        state |= (1 << 9);
    if ((mod & InputEvent.BUTTON3_MASK) != 0)
        state |= (1 << 10);
    if ((mod & InputEvent.SHIFT_MASK) != 0)
        state |= 1;
    if ((mod & InputEvent.CTRL_MASK) != 0)
        state |= 4;
    // alt -> state|=8;
    XWindow.sprite.hot.state = state;

    event.mkMotionNotify(0, window.screen.rootId, window.id, 0, x, y, x - window.x, y - window.y, state, 1);

    try {
        if (!XWindow.checkMotion(event, window)) {
            return;
        }
        if (XWindow.grab != null)
            XWindow.sendGrabbedEvent(event, false, 1);
        else
            XWindow.sendDeviceEvent(window, event, XWindow.grab, null, 1);
    } catch (Exception ee) {
    }
}

From source file:org.forester.archaeopteryx.TreePanel.java

final void mouseClicked(final MouseEvent e) {
    if (getOptions().isShowOverview() && isOvOn() && isInOv()) {
        final double w_ratio = getVisibleRect().width / getOvRectangle().getWidth();
        final double h_ratio = getVisibleRect().height / getOvRectangle().getHeight();
        double x = (e.getX() - getVisibleRect().x - getOvXPosition() - getOvRectangle().getWidth() / 2.0)
                * w_ratio;/*  ww  w.  j av a 2s .c om*/
        double y = (e.getY() - getVisibleRect().y - getOvYPosition() - getOvRectangle().getHeight() / 2.0)
                * h_ratio;
        if (x < 0) {
            x = 0;
        }
        if (y < 0) {
            y = 0;
        }
        final double max_x = getWidth() - getVisibleRect().width;
        final double max_y = getHeight() - getVisibleRect().height;
        if (x > max_x) {
            x = max_x;
        }
        if (y > max_y) {
            y = max_y;
        }
        getMainPanel().getCurrentScrollPane().getViewport()
                .setViewPosition(new Point(ForesterUtil.roundToInt(x), ForesterUtil.roundToInt(y)));
        setInOvRect(true);
        repaint();
    } else if (findNode(e.getX(), e.getY()) != null) {

        if ((_control_panel.getActionWhenNodeClicked() == NodeClickAction.SHOW_BRANCH_DATA)
                || (_control_panel.getActionWhenNodeClicked() == NodeClickAction.SHOW_DATA)) {
            _control_panel.setActionWhenNodeClicked(NodeClickAction.SHOW_DATA);
        }
        //System.out.println(_control_panel.getActionWhenNodeClicked());
        final PhylogenyNode node = findNode(e.getX(), e.getY());
        if (node != null) {
            if (!node.isRoot() && node.getParent().isCollapse()) {
                return;
            }
            _highlight_node = node;
            // Check if shift key is down
            if ((e.getModifiers() & InputEvent.SHIFT_MASK) != 0) {
                // Yes, so add to _found_nodes
                if (getFoundNodes() == null) {
                    setFoundNodes(new HashSet<PhylogenyNode>());
                }
                getFoundNodes().add(node);
                // Check if control key is down
            } else if ((e.getModifiers() & InputEvent.CTRL_MASK) != 0) {
                // Yes, so pop-up menu
                displayNodePopupMenu(node, e.getX(), e.getY());
                // Handle unadorned click
            } else {
                // Check for right mouse button
                if (e.getModifiers() == 4) {
                    displayNodePopupMenu(node, e.getX(), e.getY());
                } else {
                    // if not in _found_nodes, clear _found_nodes

                    if (_control_panel.getActionWhenNodeClicked().equals(NodeClickAction.REROOT)) {
                        // no rerooting for nodes anymore
                    } else {
                        handleClickToAction(_control_panel.getActionWhenNodeClicked(), node);
                    }

                }
            }
        }
    }

    else if (findBranch(e.getX(), e.getY()) != null) {
        final PhylogenyNode node = findBranch(e.getX(), e.getY());
        // Check for right mouse button
        if (e.getModifiers() == 4) {
            displayBranchPopupMenu(node, e.getX(), e.getY());
        } else {
            if ((_control_panel.getActionWhenNodeClicked() == NodeClickAction.SHOW_BRANCH_DATA)
                    || (_control_panel.getActionWhenNodeClicked() == NodeClickAction.SHOW_DATA)) {
                _control_panel.setActionWhenNodeClicked(NodeClickAction.SHOW_BRANCH_DATA);
            }
            handleClickToAction(_control_panel.getActionWhenNodeClicked(), node);
        }
    }

    else {

        // no node was clicked
        _highlight_node = null;

    }
    repaint();
}

From source file:org.datavyu.views.DatavyuView.java

/**
 * Constructor.//from  w  w  w  .  ja va 2 s  .com
 *
 * @param app
 *            The SingleFrameApplication that invoked this main FrameView.
 */
public DatavyuView(final SingleFrameApplication app) {
    super(app);

    KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();

    manager.addKeyEventDispatcher(new KeyEventDispatcher() {

        /**
         * Dispatches the keystroke to the correct action.
         *
         * @param evt The event that triggered this action.
         * @return true if the KeyboardFocusManager should take no further
         * action with regard to the KeyEvent; false otherwise.
         */
        @Override
        public boolean dispatchKeyEvent(final KeyEvent evt) {

            // Pass the keyevent onto the keyswitchboard so that it can
            // route it to the correct action.
            //                    spreadsheetMenuSelected(null);

            return Datavyu.getApplication().dispatchKeyEvent(evt);
        }
    });

    // generated GUI builder code
    initComponents();

    // BugzID:492 - Set the shortcut for new cell, so a keystroke that won't
    // get confused for the "carriage return". The shortcut for new cells
    // is handled in Datavyu.java
    newCellMenuItem.setAccelerator(KeyStroke.getKeyStroke('\u21A9'));

    // BugzID:521 + 468 - Define accelerator keys based on Operating system.
    int keyMask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
    weakTemporalOrderMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, keyMask));

    strongTemporalOrderMenuItem
            .setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, InputEvent.SHIFT_MASK | keyMask));

    // Set zoom in to keyMask + '+'
    zoomInMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, keyMask));

    // Set zoom out to keyMask + '-'
    zoomOutMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, keyMask));

    // Set reset zoom to keyMask + '0'
    resetZoomMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_0, keyMask));

    // Set the save accelerator to keyMask + 'S'
    saveMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, keyMask));

    // Set the save as accelerator to keyMask + shift + 'S'
    saveAsMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, keyMask | InputEvent.SHIFT_MASK));

    // Set the open accelerator to keyMask + 'o';
    openMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, keyMask));

    // Set the new accelerator to keyMask + 'N';
    newMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, keyMask));

    // Set the new accelerator to keyMask + 'L';
    newCellLeftMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L, keyMask));

    // Set the new accelerator to keyMask + 'R';
    newCellRightMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, keyMask));

    // Set the show spreadsheet accelrator to F5.
    showSpreadsheetMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0));

    // Set the undo accelerator to keyMask + 'Z';
    undoSpreadSheetMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z, keyMask));

    // Set the redo accelerator to keyMask + 'Y'
    redoSpreadSheetMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Y, keyMask));

    if (panel != null) {
        panel.deregisterListeners();
        panel.removeFileDropEventListener(this);
    }

    panel = new SpreadsheetPanel(Datavyu.getProjectController().getDB(), null);
    panel.registerListeners();
    panel.addFileDropEventListener(this);
    setComponent(panel);

    System.out.println(getComponent());

    // initialize the undo/redo system
    spreadsheetUndoManager = new SpreadsheetUndoManager();
    undoSupport = new UndoableEditSupport();
    undoSupport.addUndoableEditListener(new UndoAdapter());
    refreshUndoRedo();
    //////

    //Jakrabbit Menu
    pushMenuItem.setVisible(false);
    pullMenuItem.setVisible(false);
    jSeparator10.setVisible(false);

}

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);//from www.j  a  v a  2 s  .  c om
    editor.setInputMap(JComponent.WHEN_FOCUSED, myInputMap);
}

From source file:org.eclipse.jubula.rc.common.driver.KeyTyper.java

/**
 * @param keyStroke KeyStroke whose modifiers are requested
 * @return a List of KeyCodes (hopefully) realising the ModifierMask contained in the KeyStroke
 *///from   w ww  .j  a  v a2s . com
private List modifierKeyCodes(KeyStroke keyStroke) {
    List l = new LinkedList();
    int modifiers = keyStroke.getModifiers();
    // this is jdk 1.3 - code.
    // use ALT_DOWN_MASK instead etc. with jdk 1.4 !
    if ((modifiers & InputEvent.ALT_MASK) != 0) {
        l.add(new Integer(KeyEvent.VK_ALT));
    }
    if ((modifiers & InputEvent.ALT_GRAPH_MASK) != 0) {
        l.add(new Integer(KeyEvent.VK_ALT_GRAPH));
    }
    if ((modifiers & InputEvent.CTRL_MASK) != 0) {
        l.add(new Integer(KeyEvent.VK_CONTROL));
    }
    if ((modifiers & InputEvent.SHIFT_MASK) != 0) {
        l.add(new Integer(KeyEvent.VK_SHIFT));
    }
    if ((modifiers & InputEvent.META_MASK) != 0) {
        l.add(new Integer(KeyEvent.VK_META));
    }
    return l;
}

From source file:org.eclipse.jubula.rc.swt.driver.RobotSwtImpl.java

/**
 * /*from  w  w  w.  ja v a 2s.  c o m*/
 * @param keyStroke The key stroke. 
 * @return a list of key typers capable of generating the necessary
 *         events to simulate the modifiers of the given key stroke.
 */
private List modifierKeyTypers(KeyStroke keyStroke) {
    List l = new LinkedList();
    int modifiers = keyStroke.getModifiers();
    // this is jdk 1.3 - code.
    // use ALT_DOWN_MASK instead etc. with jdk 1.4 !
    if ((modifiers & InputEvent.ALT_MASK) != 0) {
        l.add(new KeyCodeTyper(SWT.ALT));
    }
    if ((modifiers & InputEvent.CTRL_MASK) != 0) {
        l.add(new KeyCodeTyper(SWT.CTRL));
    }
    if ((modifiers & InputEvent.SHIFT_MASK) != 0) {
        l.add(new KeyCodeTyper(SWT.SHIFT));
    }
    if ((modifiers & InputEvent.META_MASK) != 0) {
        l.add(new KeyCodeTyper(SWT.COMMAND));
    }
    return l;
}

From source file:org.jcurl.demo.tactics.old.ActionRegistry.java

KeyStroke findAccelerator(final String acc) {
    if (acc == null || "".equals(acc))
        return null;
    final Matcher m = KeyPat.matcher(acc);
    if (m.matches()) {
        int modifiers = 0;
        {/*from  www .  j  a  v  a2s . c o m*/
            final String gr = m.group(1);
            if (!"".equals(gr)) {
                final String[] mod = gr.split("-");
                for (final String mm : mod)
                    if ("CTRL".equals(mm))
                        modifiers |= InputEvent.CTRL_MASK;
                    else if ("ALT".equals(mm))
                        modifiers |= InputEvent.ALT_MASK;
                    else if ("SHIFT".equals(mm))
                        modifiers |= InputEvent.SHIFT_MASK;
                    else
                        throw new IllegalStateException(mm);
            }
        }
        if (m.group(2).length() == 1)
            return KeyStroke.getKeyStroke(m.group(2).charAt(0), modifiers);
        final Integer kc = str2key.get(m.group(2));
        if (kc == null)
            throw new IllegalStateException(m.group(2));
        return KeyStroke.getKeyStroke(kc.intValue(), modifiers);
    } else {
        // swing syntax
        final KeyStroke k = KeyStroke.getKeyStroke(acc);
        if (k == null)
            throw new IllegalArgumentException(acc);
        return k;
    }
}

From source file:org.pmedv.core.provider.ApplicationMenuBarProviderImpl.java

@SuppressWarnings("unused")
public ApplicationMenuBarProviderImpl() {

    populateKeyTable();//from w w  w . j a v a2 s  .  com

    menubar = new JMenuBar();

    try {
        JAXBContext c = JAXBContext.newInstance(ApplicationMenubar.class);

        Unmarshaller u = c.createUnmarshaller();

        ApplicationMenubar appMenuBar = (ApplicationMenubar) u
                .unmarshal(getClass().getClassLoader().getResourceAsStream("menus.xml"));

        for (ApplicationMenu currentMenu : appMenuBar.getMenus()) {

            JMenuWithId menu = new JMenuWithId(resources.getResourceByKey(currentMenu.getName()));

            menu.setMnemonic(resources.getResourceByKey(currentMenu.getName()).charAt(0));

            for (ApplicationMenuItem currentItem : currentMenu.getItems()) {

                try {

                    if (currentItem.getActionClass() != null) {

                        if (currentItem.getActionClass().equals("separator")) {
                            menu.addSeparator();
                            continue;
                        }

                        log.info("Mapping action class : " + currentItem.getActionClass());

                        try {

                            AbstractCommand command = null;
                            Class<?> clazz = Class.forName(currentItem.getActionClass());

                            if (currentItem.isBean()) {
                                command = (AbstractCommand) ctx.getBean(clazz);
                            } else {
                                command = (AbstractCommand) clazz.newInstance();
                            }

                            ImageIcon icon = null;
                            String mnemonic = null;
                            String toolTipText = null;

                            if (currentItem.getImageIcon() != null) {

                                InputStream is = getClass().getClassLoader()
                                        .getResourceAsStream(currentItem.getImageIcon());

                                if (is == null) {
                                    is = getClass().getClassLoader()
                                            .getResourceAsStream("icons/noresource_16x16.png");
                                }

                                icon = new ImageIcon(ImageIO.read(is));

                            }
                            if (currentItem.getMnemonic() != null) {
                                mnemonic = currentItem.getMnemonic();
                            }
                            if (currentItem.getToolTipText() != null) {
                                toolTipText = currentItem.getToolTipText();
                            }
                            if (currentItem.getType() != null
                                    && currentItem.getType().equals("ApplicationMenuItemType.CHECKBOX")) {

                                CmdJCheckBoxMenuItem cmdItem = new CmdJCheckBoxMenuItem(currentItem.getName(),
                                        icon, command, mnemonic, toolTipText, null);

                                if (mnemonic != null && currentItem.getModifier() != null) {

                                    if (currentItem.getModifier().equalsIgnoreCase("ctrl")) {
                                        cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(mnemonic),
                                                InputEvent.CTRL_MASK, false));
                                    } else if (currentItem.getModifier().equalsIgnoreCase("alt")) {
                                        cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(mnemonic),
                                                InputEvent.ALT_MASK, false));
                                    } else if (currentItem.getModifier().equalsIgnoreCase("shift")) {
                                        cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(mnemonic),
                                                InputEvent.SHIFT_MASK, false));
                                    }

                                }

                                menu.add(cmdItem);

                            } else {

                                JMenuItem cmdItem = new JMenuItem(command);

                                if (mnemonic != null && currentItem.getModifier() != null) {

                                    if (currentItem.getModifier().equalsIgnoreCase("ctrl")) {
                                        cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(mnemonic),
                                                InputEvent.CTRL_MASK, false));
                                    } else if (currentItem.getModifier().equalsIgnoreCase("alt")) {
                                        cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(mnemonic),
                                                InputEvent.ALT_MASK, false));
                                    } else if (currentItem.getModifier().equalsIgnoreCase("shift")) {
                                        cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(mnemonic),
                                                InputEvent.SHIFT_MASK, false));
                                    }

                                }

                                menu.add(cmdItem);

                            }

                        } catch (InstantiationException e) {
                            log.info("could not instanciate menuitem, skipping.");
                        } catch (IllegalAccessException e) {
                            log.info("could not access menuitem, skipping.");
                        }

                    }

                } catch (ClassNotFoundException e) {
                    log.info("could not find action class " + currentItem.getActionClass());
                }

            }

            if (currentMenu.getType() != null && currentMenu.getType().equalsIgnoreCase("file")) {

                JMenu openRecentMenu = new JMenu(resources.getResourceByKey("menu.recentfiles"));

                RecentFileList fileList = null;

                try {

                    String inputDir = System.getProperty("user.home") + "/." + AppContext.getName() + "/";
                    String inputFileName = "recentFiles.xml";
                    File inputFile = new File(inputDir + inputFileName);

                    if (inputFile.exists()) {
                        Unmarshaller u1 = JAXBContext.newInstance(RecentFileList.class).createUnmarshaller();
                        fileList = (RecentFileList) u1.unmarshal(inputFile);
                    }

                    if (fileList == null)
                        fileList = new RecentFileList();

                    ArrayList<String> recent = fileList.getRecentFiles();
                    Collections.reverse(recent);

                    for (String recentFile : fileList.getRecentFiles()) {
                        File file = new File(recentFile);
                        AbstractCommand openBoardAction = new OpenBoardCommand(file.getName(), file);
                        JMenuItem item = new JMenuItem(openBoardAction);
                        openRecentMenu.add(item);
                    }

                } catch (JAXBException e) {
                    e.printStackTrace();
                }

                menu.addSeparator();
                menu.add(openRecentMenu);

                JMenu openSamplesMenu = createSamplesMenu();

                menu.add(openSamplesMenu);

            }

            menu.setId("common");

            if (currentMenu.getType() != null && !currentMenu.getType().equalsIgnoreCase("help"))
                menubar.add(menu);
            else
                helpMenus.add(menu);

            menubar.setFont(new Font("SansSerif", Font.PLAIN, 12));

        }

        ApplicationPerspectiveProvider perspectiveProvider = ctx.getBean(ApplicationPerspectiveProvider.class);
        ArrayList<ApplicationPerspective> perspectives = perspectiveProvider.getPerspectives();

        JMenuWithId perspectivesMenu = new JMenuWithId("Perspectives");
        perspectivesMenu.setId("common");
        perspectivesMenu.setMnemonic('P');

        for (ApplicationPerspective perspective : perspectives) {

            ImageIcon icon = null;
            String mnemonic = null;
            String toolTipText = null;

            if (perspective.getPerspectiveIcon() != null) {

                InputStream is = getClass().getClassLoader()
                        .getResourceAsStream(perspective.getPerspectiveIcon());

                if (is != null) {
                    icon = new ImageIcon(ImageIO.read(is));
                } else {

                    is = getClass().getClassLoader().getResourceAsStream("icons/noresource_16x16.png");

                    if (is != null)
                        icon = new ImageIcon(ImageIO.read(is));

                }

            }
            if (perspective.getMnemonic() != null) {
                mnemonic = perspective.getMnemonic();
            }
            if (perspective.getToolTipText() != null) {
                toolTipText = perspective.getToolTipText();
            }

            log.info("mapping perspective class " + perspective.getPerspectiveClass());
            OpenPerspectiveCommand command = new OpenPerspectiveCommand(perspective.getId());

            JMenuItem item = new JMenuItem(command);

            if (mnemonic != null && perspective.getModifier() != null) {

                if (perspective.getModifier().equalsIgnoreCase("ctrl")) {
                    item.setAccelerator(
                            KeyStroke.getKeyStroke(keyMap.get(mnemonic), InputEvent.CTRL_MASK, false));
                } else if (perspective.getModifier().equalsIgnoreCase("alt")) {
                    item.setAccelerator(
                            KeyStroke.getKeyStroke(keyMap.get(mnemonic), InputEvent.ALT_MASK, false));
                } else if (perspective.getModifier().equalsIgnoreCase("shift")) {
                    item.setAccelerator(
                            KeyStroke.getKeyStroke(keyMap.get(mnemonic), InputEvent.SHIFT_MASK, false));
                }

            }

            perspectivesMenu.add(item);

            for (ApplicationMenu pMenu : perspective.getMenubarContributions()) {

                JMenuWithId menu = new JMenuWithId(resources.getResourceByKey(pMenu.getName()));

                // if (pMenu.getMnemonic() != null && pMenu.getMnemonic().length() > 0)               
                menu.setMnemonic(resources.getResourceByKey(pMenu.getName()).charAt(0));

                for (ApplicationMenuItem currentItem : pMenu.getItems()) {

                    try {

                        if (currentItem.getActionClass() != null) {

                            if (currentItem.getActionClass().equals("separator")) {
                                menu.addSeparator();
                                continue;
                            }

                            log.info("Mapping action class : " + currentItem.getActionClass());

                            try {

                                AbstractCommand pCommand = null;
                                Class<?> clazz = Class.forName(currentItem.getActionClass());

                                if (currentItem.isBean()) {
                                    pCommand = (AbstractCommand) ctx.getBean(clazz);
                                } else {
                                    pCommand = (AbstractCommand) clazz.newInstance();
                                }

                                ImageIcon pIcon = null;
                                String pMnemonic = null;
                                String pToolTipText = null;

                                if (currentItem.getImageIcon() != null) {

                                    InputStream is = getClass().getClassLoader()
                                            .getResourceAsStream(currentItem.getImageIcon());
                                    pIcon = new ImageIcon(ImageIO.read(is));

                                }
                                if (currentItem.getMnemonic() != null) {
                                    pMnemonic = currentItem.getMnemonic();
                                }
                                if (currentItem.getToolTipText() != null) {
                                    pToolTipText = currentItem.getToolTipText();
                                }

                                if (currentItem.getType() != null
                                        && currentItem.getType().equals("ApplicationMenuItemType.CHECKBOX")) {

                                    log.info(
                                            "Creating menu checkbox for class " + currentItem.getActionClass());

                                    JCheckBoxMenuItem cmdItem = new JCheckBoxMenuItem(pCommand);

                                    if (pMnemonic != null && currentItem.getModifier() != null) {

                                        if (currentItem.getModifier().equalsIgnoreCase("ctrl")) {
                                            cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(pMnemonic),
                                                    InputEvent.CTRL_MASK, false));
                                        } else if (currentItem.getModifier().equalsIgnoreCase("alt")) {
                                            cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(pMnemonic),
                                                    InputEvent.ALT_MASK, false));
                                        } else if (currentItem.getModifier().equalsIgnoreCase("shift")) {
                                            cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(pMnemonic),
                                                    InputEvent.SHIFT_MASK, false));
                                        }

                                    }

                                    menu.add(cmdItem);
                                    cmdItem.setSelected(true);

                                } else {

                                    log.info("Creating menu entry for class " + currentItem.getActionClass());

                                    JMenuItem cmdItem = new JMenuItem(pCommand);

                                    if (pMnemonic != null && currentItem.getModifier() != null) {

                                        if (currentItem.getModifier().equalsIgnoreCase("ctrl")) {
                                            cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(pMnemonic),
                                                    InputEvent.CTRL_MASK, false));
                                        } else if (currentItem.getModifier().equalsIgnoreCase("alt")) {
                                            cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(pMnemonic),
                                                    InputEvent.ALT_MASK, false));
                                        } else if (currentItem.getModifier().equalsIgnoreCase("shift")) {
                                            cmdItem.setAccelerator(KeyStroke.getKeyStroke(keyMap.get(pMnemonic),
                                                    InputEvent.SHIFT_MASK, false));
                                        }

                                    }

                                    menu.add(cmdItem);

                                }

                            } catch (InstantiationException e) {
                                log.info("could not instanciate menuitem, skipping.");
                            } catch (IllegalAccessException e) {
                                log.info("could not access menuitem, skipping.");
                            }

                        }

                    } catch (ClassNotFoundException e) {
                        log.info("could not find action class " + currentItem.getActionClass());
                    }

                }

                menu.setId(perspective.getId());
                menu.setVisible(false);

                menubar.add(menu);

            }

        }

        if (perspectiveProvider.getPerspectives().size() > 1) {
            menubar.add(perspectivesMenu);
        }

        for (JMenuWithId helpmenu : helpMenus) {
            menubar.add(helpmenu);
        }

        menubar.setFont(new Font("SansSerif", Font.PLAIN, 12));

    } catch (JAXBException e) {
        log.info("could not deserialize menus.");
        throw new RuntimeException("could not deserialize menus.");
    } catch (IOException e) {
        log.info("could not load menus.");
        throw new RuntimeException("could not load menus.");
    }

}