Example usage for java.awt.event InputEvent META_MASK

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

Introduction

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

Prototype

int META_MASK

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

Click Source Link

Document

The Meta key modifier constant.

Usage

From source file:Main.java

/**
 * Serializes a Keystrike to a String./*from   ww w .ja v  a 2s  . c o m*/
 * It can then be fed into KeyStroke.getKeyStroke(String).
 *
 * See: http://www.exampledepot.com/egs/javax.swing/Key2Str.html
 */
public static String keyStroke2String(KeyStroke key) {
    StringBuffer s = new StringBuffer(50);
    int m = key.getModifiers();

    if ((m & (InputEvent.SHIFT_DOWN_MASK | InputEvent.SHIFT_MASK)) != 0) {
        s.append("shift ");
    }
    if ((m & (InputEvent.CTRL_DOWN_MASK | InputEvent.CTRL_MASK)) != 0) {
        s.append("ctrl ");
    }
    if ((m & (InputEvent.META_DOWN_MASK | InputEvent.META_MASK)) != 0) {
        s.append("meta ");
    }
    if ((m & (InputEvent.ALT_DOWN_MASK | InputEvent.ALT_MASK)) != 0) {
        s.append("alt ");
    }
    if ((m & (InputEvent.BUTTON1_DOWN_MASK | InputEvent.BUTTON1_MASK)) != 0) {
        s.append("button1 ");
    }
    if ((m & (InputEvent.BUTTON2_DOWN_MASK | InputEvent.BUTTON2_MASK)) != 0) {
        s.append("button2 ");
    }
    if ((m & (InputEvent.BUTTON3_DOWN_MASK | InputEvent.BUTTON3_MASK)) != 0) {
        s.append("button3 ");
    }

    switch (key.getKeyEventType()) {
    case KeyEvent.KEY_TYPED:
        if (key.getKeyChar() == Character.MAX_VALUE) {
            s.append("unknown-typed-key ");
            break;
        }
        s.append("typed ").append(key.getKeyChar()).append(" ");
        break;
    case KeyEvent.KEY_PRESSED:
        s.append("pressed ").append(getKeyText(key.getKeyCode())).append(" ");
        break;
    case KeyEvent.KEY_RELEASED:
        s.append("released ").append(getKeyText(key.getKeyCode())).append(" ");
        break;
    default:
        s.append("unknown-event-type ");
        break;
    }

    return s.toString();
}

From source file:KeystrokeUtil.java

public static String keyStroke2String(KeyStroke key) {
    if (key == null)
        return "";
    StringBuilder s = new StringBuilder(50);
    int m = key.getModifiers();

    if ((m & (InputEvent.CTRL_DOWN_MASK | InputEvent.CTRL_MASK)) != 0) {
        s.append("Ctrl+");
    }/*w ww.  j av a  2s . c  o m*/
    if ((m & (InputEvent.META_DOWN_MASK | InputEvent.META_MASK)) != 0) {
        s.append("Meta+");
    }
    if ((m & (InputEvent.ALT_DOWN_MASK | InputEvent.ALT_MASK)) != 0) {
        s.append("Alt+");
    }
    if ((m & (InputEvent.SHIFT_DOWN_MASK | InputEvent.SHIFT_MASK)) != 0) {
        s.append("Shift+");
    }
    if ((m & (InputEvent.BUTTON1_DOWN_MASK | InputEvent.BUTTON1_MASK)) != 0) {
        s.append("Button1+");
    }
    if ((m & (InputEvent.BUTTON2_DOWN_MASK | InputEvent.BUTTON2_MASK)) != 0) {
        s.append("Button2+");
    }
    if ((m & (InputEvent.BUTTON3_DOWN_MASK | InputEvent.BUTTON3_MASK)) != 0) {
        s.append("Button3+");
    }

    switch (key.getKeyEventType()) {
    case KeyEvent.KEY_TYPED:
        s.append(key.getKeyChar() + " ");
        break;
    case KeyEvent.KEY_PRESSED:
    case KeyEvent.KEY_RELEASED:
        s.append(getKeyText(key.getKeyCode()) + " ");
        break;
    default:
        s.append("unknown-event-type ");
        break;
    }

    return s.toString();
}

From source file:Main.java

static void keyStroke2String(KeyStroke key) {
    int m = key.getModifiers();

    if ((m & (InputEvent.SHIFT_DOWN_MASK | InputEvent.SHIFT_MASK)) != 0) {
        System.out.println("shift ");
    }/*from   w ww . java2 s.  co  m*/
    if ((m & (InputEvent.CTRL_DOWN_MASK | InputEvent.CTRL_MASK)) != 0) {
        System.out.println("ctrl ");
    }
    if ((m & (InputEvent.META_DOWN_MASK | InputEvent.META_MASK)) != 0) {
        System.out.println("meta ");
    }
    if ((m & (InputEvent.ALT_DOWN_MASK | InputEvent.ALT_MASK)) != 0) {
        System.out.println("alt ");
    }
    if ((m & (InputEvent.BUTTON1_DOWN_MASK | InputEvent.BUTTON1_MASK)) != 0) {
        System.out.println("button1 ");
    }
    if ((m & (InputEvent.BUTTON2_DOWN_MASK | InputEvent.BUTTON2_MASK)) != 0) {
        System.out.println("button2 ");
    }
    if ((m & (InputEvent.BUTTON3_DOWN_MASK | InputEvent.BUTTON3_MASK)) != 0) {
        System.out.println("button3 ");
    }
    switch (key.getKeyEventType()) {
    case KeyEvent.KEY_TYPED:
        System.out.println("typed ");
        System.out.println(key.getKeyChar() + " ");
        break;
    case KeyEvent.KEY_PRESSED:
        System.out.println("pressed ");
        System.out.println(getKeyText(key.getKeyCode()) + " ");
        break;
    case KeyEvent.KEY_RELEASED:
        System.out.println("released ");
        System.out.println(getKeyText(key.getKeyCode()) + " ");
        break;
    default:
        System.out.println("unknown-event-type ");
        break;
    }
}

From source file:Main.java

static void keyStroke2String(KeyStroke key) {
    int m = key.getModifiers();

    if ((m & (InputEvent.SHIFT_DOWN_MASK | InputEvent.SHIFT_MASK)) != 0) {
        System.out.println("shift ");
    }//from w ww .j ava2  s .c  om
    if ((m & (InputEvent.CTRL_DOWN_MASK | InputEvent.CTRL_MASK)) != 0) {
        System.out.println("ctrl ");
    }
    if ((m & (InputEvent.META_DOWN_MASK | InputEvent.META_MASK)) != 0) {
        System.out.println("meta ");
    }
    if ((m & (InputEvent.ALT_DOWN_MASK | InputEvent.ALT_MASK)) != 0) {
        System.out.println("alt ");
    }
    if ((m & (InputEvent.BUTTON1_DOWN_MASK | InputEvent.BUTTON1_MASK)) != 0) {
        System.out.println("button1 ");
    }
    if ((m & (InputEvent.BUTTON2_DOWN_MASK | InputEvent.BUTTON2_MASK)) != 0) {
        System.out.println("button2 ");
    }
    if ((m & (InputEvent.BUTTON3_DOWN_MASK | InputEvent.BUTTON3_MASK)) != 0) {
        System.out.println("button3 ");
    }

    switch (key.getKeyEventType()) {
    case KeyEvent.KEY_TYPED:
        System.out.println("typed ");
        System.out.println(key.getKeyChar() + " ");
        break;
    case KeyEvent.KEY_PRESSED:
        System.out.println("pressed ");
        System.out.println(getKeyText(key.getKeyCode()) + " ");
        break;
    case KeyEvent.KEY_RELEASED:
        System.out.println("released ");
        System.out.println(getKeyText(key.getKeyCode()) + " ");
        break;
    default:
        System.out.println("unknown-event-type ");
        break;
    }
}

From source file:edu.umn.ecology.populus.plot.BasicPlotCanvas.java

private void jbInit() throws Exception {
    /*// w w w .j ava 2s. c  o m
    if( info != null ) {
       mainCaption = new HTMLLabel( info.getMainCaption() );
       xCaption = new HTMLLabel( info.getXCaptions()[0] );
       yCaption = new HTMLLabel( info.getYCaptions()[0] );
       yCaption.setDirection( HTMLLabel.DOWN_TO_UP );
    } else {
       mainCaption = new HTMLLabel( "Main Caption" );
       xCaption = new HTMLLabel( "X Caption" );
       yCaption = new HTMLLabel( "Y Caption" );
    }
     */
    //*
    if (info != null) {
        mainCaption = new HTMLMultiLabel(info.getMainCaption());
        xCaption = new HTMLMultiLabel(info.getXCaptions());
        yCaption = new HTMLMultiLabel(info.getYCaptions());
        yCaption.setDirection(HTMLLabel.DOWN_TO_UP);
    } else {
        mainCaption = new HTMLMultiLabel("Main Caption");
        xCaption = new HTMLMultiLabel("X Caption");
        yCaption = new HTMLMultiLabel("Y Caption");
        yCaption.setDirection(HTMLLabel.DOWN_TO_UP);
    }
    setLayout(borderLayout1);
    if (PopPreferencesStorage.isUseJFreeClass()) {
        NumberAxis yAxis = new NumberAxis(null);
        NumberAxis xAxis = new NumberAxis(null);
        xAxis.setAutoRangeIncludesZero(false);

        AbstractXYItemRenderer renderer = null;
        if (info.isBarChart) {
            renderer = new XYBarRenderer();
        } else {
            renderer = new XYLineAndShapeRenderer(true, false);
        }

        XYPlot plot = new XYPlot(null, xAxis, yAxis, renderer);
        plot.setOrientation(PlotOrientation.VERTICAL);

        JFreeChart jfchart = new JFreeChart(null, null, plot, false);
        jfchartpanel = new ChartPanel(jfchart);
        plot.setBackgroundPaint(ColorScheme.bG);

        info.styleJFree(jfchart);
        add(jfchartpanel, MacroLayout.CENTER);
    } else {
        chart = new JCChart(JCChart.PLOT);
        info.styleJC(chart);
        chart.setBackground(ColorScheme.bG);
        chart.setAllowUserChanges(true);
        chart.setTrigger(0, new EventTrigger(InputEvent.SHIFT_MASK, EventTrigger.CUSTOMIZE));
        chart.setTrigger(1, new EventTrigger(InputEvent.BUTTON1_MASK, EventTrigger.ZOOM));
        chart.setResetKey('r');
        chart.addMouseListener(new java.awt.event.MouseAdapter() {

            public void mouseClicked(java.awt.event.MouseEvent e) {
                if ((e.getModifiers() & InputEvent.META_MASK) != 0) {
                    info.setAxis(chart);
                    chart.reset();
                }
            }
        });
        chart.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
        chart.setWarningDialog(false);
        add(chart, MacroLayout.CENTER);
    }
    setBGColor();
    add(mainCaption, MacroLayout.NORTH);
    add(xCaption, MacroLayout.SOUTH);
    add(yCaption, MacroLayout.WEST);
}

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  a2 s. 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

/**
 * /*  w w w  . j  a  va2 s. 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.piraso.ui.base.ContextMonitorTopComponent.java

private void initKeyboardActions() {
    Action findAction = new AbstractAction() {
        @Override//  ww  w  .  j a  va  2  s  .c  o m
        public void actionPerformed(ActionEvent e) {
            searcher.reset();
            btnSearch.setSelected(!btnSearch.isSelected());
            btnSearchActionPerformed(e);
        }
    };

    Action nextAction = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            btnNextActionPerformed(e);
        }
    };

    KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.META_MASK);
    registerKeyboardAction(findAction, stroke, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
    txtSearch.registerKeyboardAction(findAction, stroke, JComponent.WHEN_FOCUSED);

    stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
    txtSearch.registerKeyboardAction(nextAction, stroke, JComponent.WHEN_FOCUSED);
}

From source file:org.sikuli.ide.SikuliIDE.java

private void initShortcutKeys() {
    final int scMask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
    Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() {
        private boolean isKeyNextTab(java.awt.event.KeyEvent ke) {
            if (ke.getKeyCode() == java.awt.event.KeyEvent.VK_TAB
                    && ke.getModifiers() == InputEvent.CTRL_MASK) {
                return true;
            }//from ww w .j a  va 2  s  .  c om
            if (ke.getKeyCode() == java.awt.event.KeyEvent.VK_CLOSE_BRACKET
                    && ke.getModifiers() == (InputEvent.META_MASK | InputEvent.SHIFT_MASK)) {
                return true;
            }
            return false;
        }

        private boolean isKeyPrevTab(java.awt.event.KeyEvent ke) {
            if (ke.getKeyCode() == java.awt.event.KeyEvent.VK_TAB
                    && ke.getModifiers() == (InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK)) {
                return true;
            }
            if (ke.getKeyCode() == java.awt.event.KeyEvent.VK_OPEN_BRACKET
                    && ke.getModifiers() == (InputEvent.META_MASK | InputEvent.SHIFT_MASK)) {
                return true;
            }
            return false;
        }

        public void eventDispatched(AWTEvent e) {
            java.awt.event.KeyEvent ke = (java.awt.event.KeyEvent) e;
            //Debug.log(ke.toString());
            if (ke.getID() == java.awt.event.KeyEvent.KEY_PRESSED) {
                if (isKeyNextTab(ke)) {
                    nextTab();
                } else if (isKeyPrevTab(ke)) {
                    prevTab();
                }
            }
        }
    }, AWTEvent.KEY_EVENT_MASK);

}