Example usage for java.awt.event KeyEvent VK_COMMA

List of usage examples for java.awt.event KeyEvent VK_COMMA

Introduction

In this page you can find the example usage for java.awt.event KeyEvent VK_COMMA.

Prototype

int VK_COMMA

To view the source code for java.awt.event KeyEvent VK_COMMA.

Click Source Link

Document

Constant for the comma key, ","

Usage

From source file:Main.java

public static String getKeyText(int keyCode) {
    if (keyCode >= KeyEvent.VK_0 && keyCode <= KeyEvent.VK_9
            || keyCode >= KeyEvent.VK_A && keyCode <= KeyEvent.VK_Z) {
        return String.valueOf((char) keyCode);
    }//from   w  ww . j  ava 2s . c  o m

    switch (keyCode) {
    case KeyEvent.VK_COMMA:
        return "COMMA";
    case KeyEvent.VK_PERIOD:
        return "PERIOD";
    case KeyEvent.VK_SLASH:
        return "SLASH";
    case KeyEvent.VK_SEMICOLON:
        return "SEMICOLON";
    case KeyEvent.VK_EQUALS:
        return "EQUALS";
    case KeyEvent.VK_OPEN_BRACKET:
        return "OPEN_BRACKET";
    case KeyEvent.VK_BACK_SLASH:
        return "BACK_SLASH";
    case KeyEvent.VK_CLOSE_BRACKET:
        return "CLOSE_BRACKET";

    case KeyEvent.VK_ENTER:
        return "ENTER";
    case KeyEvent.VK_BACK_SPACE:
        return "BACK_SPACE";
    case KeyEvent.VK_TAB:
        return "TAB";
    case KeyEvent.VK_CANCEL:
        return "CANCEL";
    case KeyEvent.VK_CLEAR:
        return "CLEAR";
    case KeyEvent.VK_SHIFT:
        return "SHIFT";
    case KeyEvent.VK_CONTROL:
        return "CONTROL";
    case KeyEvent.VK_ALT:
        return "ALT";
    case KeyEvent.VK_PAUSE:
        return "PAUSE";
    case KeyEvent.VK_CAPS_LOCK:
        return "CAPS_LOCK";
    case KeyEvent.VK_ESCAPE:
        return "ESCAPE";
    case KeyEvent.VK_SPACE:
        return "SPACE";
    case KeyEvent.VK_PAGE_UP:
        return "PAGE_UP";
    case KeyEvent.VK_PAGE_DOWN:
        return "PAGE_DOWN";
    case KeyEvent.VK_END:
        return "END";
    case KeyEvent.VK_HOME:
        return "HOME";
    case KeyEvent.VK_LEFT:
        return "LEFT";
    case KeyEvent.VK_UP:
        return "UP";
    case KeyEvent.VK_RIGHT:
        return "RIGHT";
    case KeyEvent.VK_DOWN:
        return "DOWN";

    // numpad numeric keys handled below
    case KeyEvent.VK_MULTIPLY:
        return "MULTIPLY";
    case KeyEvent.VK_ADD:
        return "ADD";
    case KeyEvent.VK_SEPARATOR:
        return "SEPARATOR";
    case KeyEvent.VK_SUBTRACT:
        return "SUBTRACT";
    case KeyEvent.VK_DECIMAL:
        return "DECIMAL";
    case KeyEvent.VK_DIVIDE:
        return "DIVIDE";
    case KeyEvent.VK_DELETE:
        return "DELETE";
    case KeyEvent.VK_NUM_LOCK:
        return "NUM_LOCK";
    case KeyEvent.VK_SCROLL_LOCK:
        return "SCROLL_LOCK";

    case KeyEvent.VK_F1:
        return "F1";
    case KeyEvent.VK_F2:
        return "F2";
    case KeyEvent.VK_F3:
        return "F3";
    case KeyEvent.VK_F4:
        return "F4";
    case KeyEvent.VK_F5:
        return "F5";
    case KeyEvent.VK_F6:
        return "F6";
    case KeyEvent.VK_F7:
        return "F7";
    case KeyEvent.VK_F8:
        return "F8";
    case KeyEvent.VK_F9:
        return "F9";
    case KeyEvent.VK_F10:
        return "F10";
    case KeyEvent.VK_F11:
        return "F11";
    case KeyEvent.VK_F12:
        return "F12";
    case KeyEvent.VK_F13:
        return "F13";
    case KeyEvent.VK_F14:
        return "F14";
    case KeyEvent.VK_F15:
        return "F15";
    case KeyEvent.VK_F16:
        return "F16";
    case KeyEvent.VK_F17:
        return "F17";
    case KeyEvent.VK_F18:
        return "F18";
    case KeyEvent.VK_F19:
        return "F19";
    case KeyEvent.VK_F20:
        return "F20";
    case KeyEvent.VK_F21:
        return "F21";
    case KeyEvent.VK_F22:
        return "F22";
    case KeyEvent.VK_F23:
        return "F23";
    case KeyEvent.VK_F24:
        return "F24";

    case KeyEvent.VK_PRINTSCREEN:
        return "PRINTSCREEN";
    case KeyEvent.VK_INSERT:
        return "INSERT";
    case KeyEvent.VK_HELP:
        return "HELP";
    case KeyEvent.VK_META:
        return "META";
    case KeyEvent.VK_BACK_QUOTE:
        return "BACK_QUOTE";
    case KeyEvent.VK_QUOTE:
        return "QUOTE";

    case KeyEvent.VK_KP_UP:
        return "KP_UP";
    case KeyEvent.VK_KP_DOWN:
        return "KP_DOWN";
    case KeyEvent.VK_KP_LEFT:
        return "KP_LEFT";
    case KeyEvent.VK_KP_RIGHT:
        return "KP_RIGHT";

    case KeyEvent.VK_DEAD_GRAVE:
        return "DEAD_GRAVE";
    case KeyEvent.VK_DEAD_ACUTE:
        return "DEAD_ACUTE";
    case KeyEvent.VK_DEAD_CIRCUMFLEX:
        return "DEAD_CIRCUMFLEX";
    case KeyEvent.VK_DEAD_TILDE:
        return "DEAD_TILDE";
    case KeyEvent.VK_DEAD_MACRON:
        return "DEAD_MACRON";
    case KeyEvent.VK_DEAD_BREVE:
        return "DEAD_BREVE";
    case KeyEvent.VK_DEAD_ABOVEDOT:
        return "DEAD_ABOVEDOT";
    case KeyEvent.VK_DEAD_DIAERESIS:
        return "DEAD_DIAERESIS";
    case KeyEvent.VK_DEAD_ABOVERING:
        return "DEAD_ABOVERING";
    case KeyEvent.VK_DEAD_DOUBLEACUTE:
        return "DEAD_DOUBLEACUTE";
    case KeyEvent.VK_DEAD_CARON:
        return "DEAD_CARON";
    case KeyEvent.VK_DEAD_CEDILLA:
        return "DEAD_CEDILLA";
    case KeyEvent.VK_DEAD_OGONEK:
        return "DEAD_OGONEK";
    case KeyEvent.VK_DEAD_IOTA:
        return "DEAD_IOTA";
    case KeyEvent.VK_DEAD_VOICED_SOUND:
        return "DEAD_VOICED_SOUND";
    case KeyEvent.VK_DEAD_SEMIVOICED_SOUND:
        return "DEAD_SEMIVOICED_SOUND";

    case KeyEvent.VK_AMPERSAND:
        return "AMPERSAND";
    case KeyEvent.VK_ASTERISK:
        return "ASTERISK";
    case KeyEvent.VK_QUOTEDBL:
        return "QUOTEDBL";
    case KeyEvent.VK_LESS:
        return "LESS";
    case KeyEvent.VK_GREATER:
        return "GREATER";
    case KeyEvent.VK_BRACELEFT:
        return "BRACELEFT";
    case KeyEvent.VK_BRACERIGHT:
        return "BRACERIGHT";
    case KeyEvent.VK_AT:
        return "AT";
    case KeyEvent.VK_COLON:
        return "COLON";
    case KeyEvent.VK_CIRCUMFLEX:
        return "CIRCUMFLEX";
    case KeyEvent.VK_DOLLAR:
        return "DOLLAR";
    case KeyEvent.VK_EURO_SIGN:
        return "EURO_SIGN";
    case KeyEvent.VK_EXCLAMATION_MARK:
        return "EXCLAMATION_MARK";
    case KeyEvent.VK_INVERTED_EXCLAMATION_MARK:
        return "INVERTED_EXCLAMATION_MARK";
    case KeyEvent.VK_LEFT_PARENTHESIS:
        return "LEFT_PARENTHESIS";
    case KeyEvent.VK_NUMBER_SIGN:
        return "NUMBER_SIGN";
    case KeyEvent.VK_MINUS:
        return "MINUS";
    case KeyEvent.VK_PLUS:
        return "PLUS";
    case KeyEvent.VK_RIGHT_PARENTHESIS:
        return "RIGHT_PARENTHESIS";
    case KeyEvent.VK_UNDERSCORE:
        return "UNDERSCORE";

    case KeyEvent.VK_FINAL:
        return "FINAL";
    case KeyEvent.VK_CONVERT:
        return "CONVERT";
    case KeyEvent.VK_NONCONVERT:
        return "NONCONVERT";
    case KeyEvent.VK_ACCEPT:
        return "ACCEPT";
    case KeyEvent.VK_MODECHANGE:
        return "MODECHANGE";
    case KeyEvent.VK_KANA:
        return "KANA";
    case KeyEvent.VK_KANJI:
        return "KANJI";
    case KeyEvent.VK_ALPHANUMERIC:
        return "ALPHANUMERIC";
    case KeyEvent.VK_KATAKANA:
        return "KATAKANA";
    case KeyEvent.VK_HIRAGANA:
        return "HIRAGANA";
    case KeyEvent.VK_FULL_WIDTH:
        return "FULL_WIDTH";
    case KeyEvent.VK_HALF_WIDTH:
        return "HALF_WIDTH";
    case KeyEvent.VK_ROMAN_CHARACTERS:
        return "ROMAN_CHARACTERS";
    case KeyEvent.VK_ALL_CANDIDATES:
        return "ALL_CANDIDATES";
    case KeyEvent.VK_PREVIOUS_CANDIDATE:
        return "PREVIOUS_CANDIDATE";
    case KeyEvent.VK_CODE_INPUT:
        return "CODE_INPUT";
    case KeyEvent.VK_JAPANESE_KATAKANA:
        return "JAPANESE_KATAKANA";
    case KeyEvent.VK_JAPANESE_HIRAGANA:
        return "JAPANESE_HIRAGANA";
    case KeyEvent.VK_JAPANESE_ROMAN:
        return "JAPANESE_ROMAN";
    case KeyEvent.VK_KANA_LOCK:
        return "KANA_LOCK";
    case KeyEvent.VK_INPUT_METHOD_ON_OFF:
        return "INPUT_METHOD_ON_OFF";

    case KeyEvent.VK_AGAIN:
        return "AGAIN";
    case KeyEvent.VK_UNDO:
        return "UNDO";
    case KeyEvent.VK_COPY:
        return "COPY";
    case KeyEvent.VK_PASTE:
        return "PASTE";
    case KeyEvent.VK_CUT:
        return "CUT";
    case KeyEvent.VK_FIND:
        return "FIND";
    case KeyEvent.VK_PROPS:
        return "PROPS";
    case KeyEvent.VK_STOP:
        return "STOP";

    case KeyEvent.VK_COMPOSE:
        return "COMPOSE";
    case KeyEvent.VK_ALT_GRAPH:
        return "ALT_GRAPH";
    }

    if (keyCode >= KeyEvent.VK_NUMPAD0 && keyCode <= KeyEvent.VK_NUMPAD9) {
        char c = (char) (keyCode - KeyEvent.VK_NUMPAD0 + '0');
        return "NUMPAD" + c;
    }

    return "unknown(0x" + Integer.toString(keyCode, 16) + ")";
}

From source file:Main.java

static String getKeyText(int keyCode) {
    if (keyCode >= KeyEvent.VK_0 && keyCode <= KeyEvent.VK_9
            || keyCode >= KeyEvent.VK_A && keyCode <= KeyEvent.VK_Z) {
        return String.valueOf((char) keyCode);
    }//from  w ww .  j  a  v  a  2 s . co  m
    switch (keyCode) {
    case KeyEvent.VK_COMMA:
        return "COMMA";
    case KeyEvent.VK_PERIOD:
        return "PERIOD";
    case KeyEvent.VK_SLASH:
        return "SLASH";
    case KeyEvent.VK_SEMICOLON:
        return "SEMICOLON";
    case KeyEvent.VK_EQUALS:
        return "EQUALS";
    case KeyEvent.VK_OPEN_BRACKET:
        return "OPEN_BRACKET";
    case KeyEvent.VK_BACK_SLASH:
        return "BACK_SLASH";
    case KeyEvent.VK_CLOSE_BRACKET:
        return "CLOSE_BRACKET";
    case KeyEvent.VK_ENTER:
        return "ENTER";
    case KeyEvent.VK_BACK_SPACE:
        return "BACK_SPACE";
    case KeyEvent.VK_TAB:
        return "TAB";
    case KeyEvent.VK_CANCEL:
        return "CANCEL";
    case KeyEvent.VK_CLEAR:
        return "CLEAR";
    case KeyEvent.VK_SHIFT:
        return "SHIFT";
    case KeyEvent.VK_CONTROL:
        return "CONTROL";
    case KeyEvent.VK_ALT:
        return "ALT";
    case KeyEvent.VK_PAUSE:
        return "PAUSE";
    case KeyEvent.VK_CAPS_LOCK:
        return "CAPS_LOCK";
    case KeyEvent.VK_ESCAPE:
        return "ESCAPE";
    case KeyEvent.VK_SPACE:
        return "SPACE";
    case KeyEvent.VK_PAGE_UP:
        return "PAGE_UP";
    case KeyEvent.VK_PAGE_DOWN:
        return "PAGE_DOWN";
    case KeyEvent.VK_END:
        return "END";
    case KeyEvent.VK_HOME:
        return "HOME";
    case KeyEvent.VK_LEFT:
        return "LEFT";
    case KeyEvent.VK_UP:
        return "UP";
    case KeyEvent.VK_RIGHT:
        return "RIGHT";
    case KeyEvent.VK_DOWN:
        return "DOWN";
    case KeyEvent.VK_MULTIPLY:
        return "MULTIPLY";
    case KeyEvent.VK_ADD:
        return "ADD";
    case KeyEvent.VK_SEPARATOR:
        return "SEPARATOR";
    case KeyEvent.VK_SUBTRACT:
        return "SUBTRACT";
    case KeyEvent.VK_DECIMAL:
        return "DECIMAL";
    case KeyEvent.VK_DIVIDE:
        return "DIVIDE";
    case KeyEvent.VK_DELETE:
        return "DELETE";
    case KeyEvent.VK_NUM_LOCK:
        return "NUM_LOCK";
    case KeyEvent.VK_SCROLL_LOCK:
        return "SCROLL_LOCK";
    case KeyEvent.VK_F1:
        return "F1";
    case KeyEvent.VK_F2:
        return "F2";
    case KeyEvent.VK_F3:
        return "F3";
    case KeyEvent.VK_F4:
        return "F4";
    case KeyEvent.VK_F5:
        return "F5";
    case KeyEvent.VK_F6:
        return "F6";
    case KeyEvent.VK_F7:
        return "F7";
    case KeyEvent.VK_F8:
        return "F8";
    case KeyEvent.VK_F9:
        return "F9";
    case KeyEvent.VK_F10:
        return "F10";
    case KeyEvent.VK_F11:
        return "F11";
    case KeyEvent.VK_F12:
        return "F12";
    case KeyEvent.VK_F13:
        return "F13";
    case KeyEvent.VK_F14:
        return "F14";
    case KeyEvent.VK_F15:
        return "F15";
    case KeyEvent.VK_F16:
        return "F16";
    case KeyEvent.VK_F17:
        return "F17";
    case KeyEvent.VK_F18:
        return "F18";
    case KeyEvent.VK_F19:
        return "F19";
    case KeyEvent.VK_F20:
        return "F20";
    case KeyEvent.VK_F21:
        return "F21";
    case KeyEvent.VK_F22:
        return "F22";
    case KeyEvent.VK_F23:
        return "F23";
    case KeyEvent.VK_F24:
        return "F24";
    case KeyEvent.VK_PRINTSCREEN:
        return "PRINTSCREEN";
    case KeyEvent.VK_INSERT:
        return "INSERT";
    case KeyEvent.VK_HELP:
        return "HELP";
    case KeyEvent.VK_META:
        return "META";
    case KeyEvent.VK_BACK_QUOTE:
        return "BACK_QUOTE";
    case KeyEvent.VK_QUOTE:
        return "QUOTE";
    case KeyEvent.VK_KP_UP:
        return "KP_UP";
    case KeyEvent.VK_KP_DOWN:
        return "KP_DOWN";
    case KeyEvent.VK_KP_LEFT:
        return "KP_LEFT";
    case KeyEvent.VK_KP_RIGHT:
        return "KP_RIGHT";
    case KeyEvent.VK_DEAD_GRAVE:
        return "DEAD_GRAVE";
    case KeyEvent.VK_DEAD_ACUTE:
        return "DEAD_ACUTE";
    case KeyEvent.VK_DEAD_CIRCUMFLEX:
        return "DEAD_CIRCUMFLEX";
    case KeyEvent.VK_DEAD_TILDE:
        return "DEAD_TILDE";
    case KeyEvent.VK_DEAD_MACRON:
        return "DEAD_MACRON";
    case KeyEvent.VK_DEAD_BREVE:
        return "DEAD_BREVE";
    case KeyEvent.VK_DEAD_ABOVEDOT:
        return "DEAD_ABOVEDOT";
    case KeyEvent.VK_DEAD_DIAERESIS:
        return "DEAD_DIAERESIS";
    case KeyEvent.VK_DEAD_ABOVERING:
        return "DEAD_ABOVERING";
    case KeyEvent.VK_DEAD_DOUBLEACUTE:
        return "DEAD_DOUBLEACUTE";
    case KeyEvent.VK_DEAD_CARON:
        return "DEAD_CARON";
    case KeyEvent.VK_DEAD_CEDILLA:
        return "DEAD_CEDILLA";
    case KeyEvent.VK_DEAD_OGONEK:
        return "DEAD_OGONEK";
    case KeyEvent.VK_DEAD_IOTA:
        return "DEAD_IOTA";
    case KeyEvent.VK_DEAD_VOICED_SOUND:
        return "DEAD_VOICED_SOUND";
    case KeyEvent.VK_DEAD_SEMIVOICED_SOUND:
        return "DEAD_SEMIVOICED_SOUND";
    case KeyEvent.VK_AMPERSAND:
        return "AMPERSAND";
    case KeyEvent.VK_ASTERISK:
        return "ASTERISK";
    case KeyEvent.VK_QUOTEDBL:
        return "QUOTEDBL";
    case KeyEvent.VK_LESS:
        return "LESS";
    case KeyEvent.VK_GREATER:
        return "GREATER";
    case KeyEvent.VK_BRACELEFT:
        return "BRACELEFT";
    case KeyEvent.VK_BRACERIGHT:
        return "BRACERIGHT";
    case KeyEvent.VK_AT:
        return "AT";
    case KeyEvent.VK_COLON:
        return "COLON";
    case KeyEvent.VK_CIRCUMFLEX:
        return "CIRCUMFLEX";
    case KeyEvent.VK_DOLLAR:
        return "DOLLAR";
    case KeyEvent.VK_EURO_SIGN:
        return "EURO_SIGN";
    case KeyEvent.VK_EXCLAMATION_MARK:
        return "EXCLAMATION_MARK";
    case KeyEvent.VK_INVERTED_EXCLAMATION_MARK:
        return "INVERTED_EXCLAMATION_MARK";
    case KeyEvent.VK_LEFT_PARENTHESIS:
        return "LEFT_PARENTHESIS";
    case KeyEvent.VK_NUMBER_SIGN:
        return "NUMBER_SIGN";
    case KeyEvent.VK_MINUS:
        return "MINUS";
    case KeyEvent.VK_PLUS:
        return "PLUS";
    case KeyEvent.VK_RIGHT_PARENTHESIS:
        return "RIGHT_PARENTHESIS";
    case KeyEvent.VK_UNDERSCORE:
        return "UNDERSCORE";
    case KeyEvent.VK_FINAL:
        return "FINAL";
    case KeyEvent.VK_CONVERT:
        return "CONVERT";
    case KeyEvent.VK_NONCONVERT:
        return "NONCONVERT";
    case KeyEvent.VK_ACCEPT:
        return "ACCEPT";
    case KeyEvent.VK_MODECHANGE:
        return "MODECHANGE";
    case KeyEvent.VK_KANA:
        return "KANA";
    case KeyEvent.VK_KANJI:
        return "KANJI";
    case KeyEvent.VK_ALPHANUMERIC:
        return "ALPHANUMERIC";
    case KeyEvent.VK_KATAKANA:
        return "KATAKANA";
    case KeyEvent.VK_HIRAGANA:
        return "HIRAGANA";
    case KeyEvent.VK_FULL_WIDTH:
        return "FULL_WIDTH";
    case KeyEvent.VK_HALF_WIDTH:
        return "HALF_WIDTH";
    case KeyEvent.VK_ROMAN_CHARACTERS:
        return "ROMAN_CHARACTERS";
    case KeyEvent.VK_ALL_CANDIDATES:
        return "ALL_CANDIDATES";
    case KeyEvent.VK_PREVIOUS_CANDIDATE:
        return "PREVIOUS_CANDIDATE";
    case KeyEvent.VK_CODE_INPUT:
        return "CODE_INPUT";
    case KeyEvent.VK_JAPANESE_KATAKANA:
        return "JAPANESE_KATAKANA";
    case KeyEvent.VK_JAPANESE_HIRAGANA:
        return "JAPANESE_HIRAGANA";
    case KeyEvent.VK_JAPANESE_ROMAN:
        return "JAPANESE_ROMAN";
    case KeyEvent.VK_KANA_LOCK:
        return "KANA_LOCK";
    case KeyEvent.VK_INPUT_METHOD_ON_OFF:
        return "INPUT_METHOD_ON_OFF";

    case KeyEvent.VK_AGAIN:
        return "AGAIN";
    case KeyEvent.VK_UNDO:
        return "UNDO";
    case KeyEvent.VK_COPY:
        return "COPY";
    case KeyEvent.VK_PASTE:
        return "PASTE";
    case KeyEvent.VK_CUT:
        return "CUT";
    case KeyEvent.VK_FIND:
        return "FIND";
    case KeyEvent.VK_PROPS:
        return "PROPS";
    case KeyEvent.VK_STOP:
        return "STOP";

    case KeyEvent.VK_COMPOSE:
        return "COMPOSE";
    case KeyEvent.VK_ALT_GRAPH:
        return "ALT_GRAPH";
    }

    if (keyCode >= KeyEvent.VK_NUMPAD0 && keyCode <= KeyEvent.VK_NUMPAD9) {
        char c = (char) (keyCode - KeyEvent.VK_NUMPAD0 + '0');
        return "NUMPAD" + c;
    }

    return "unknown(0x" + Integer.toString(keyCode, 16) + ")";
}

From source file:Main.java

static String getKeyText(int keyCode) {
    if (keyCode >= KeyEvent.VK_0 && keyCode <= KeyEvent.VK_9
            || keyCode >= KeyEvent.VK_A && keyCode <= KeyEvent.VK_Z) {
        return String.valueOf((char) keyCode);
    }//w w  w .  ja  v  a  2 s  . co  m
    switch (keyCode) {
    case KeyEvent.VK_COMMA:
        return "COMMA";
    case KeyEvent.VK_PERIOD:
        return "PERIOD";
    case KeyEvent.VK_SLASH:
        return "SLASH";
    case KeyEvent.VK_SEMICOLON:
        return "SEMICOLON";
    case KeyEvent.VK_EQUALS:
        return "EQUALS";
    case KeyEvent.VK_OPEN_BRACKET:
        return "OPEN_BRACKET";
    case KeyEvent.VK_BACK_SLASH:
        return "BACK_SLASH";
    case KeyEvent.VK_CLOSE_BRACKET:
        return "CLOSE_BRACKET";
    case KeyEvent.VK_ENTER:
        return "ENTER";
    case KeyEvent.VK_BACK_SPACE:
        return "BACK_SPACE";
    case KeyEvent.VK_TAB:
        return "TAB";
    case KeyEvent.VK_CANCEL:
        return "CANCEL";
    case KeyEvent.VK_CLEAR:
        return "CLEAR";
    case KeyEvent.VK_SHIFT:
        return "SHIFT";
    case KeyEvent.VK_CONTROL:
        return "CONTROL";
    case KeyEvent.VK_ALT:
        return "ALT";
    case KeyEvent.VK_PAUSE:
        return "PAUSE";
    case KeyEvent.VK_CAPS_LOCK:
        return "CAPS_LOCK";
    case KeyEvent.VK_ESCAPE:
        return "ESCAPE";
    case KeyEvent.VK_SPACE:
        return "SPACE";
    case KeyEvent.VK_PAGE_UP:
        return "PAGE_UP";
    case KeyEvent.VK_PAGE_DOWN:
        return "PAGE_DOWN";
    case KeyEvent.VK_END:
        return "END";
    case KeyEvent.VK_HOME:
        return "HOME";
    case KeyEvent.VK_LEFT:
        return "LEFT";
    case KeyEvent.VK_UP:
        return "UP";
    case KeyEvent.VK_RIGHT:
        return "RIGHT";
    case KeyEvent.VK_DOWN:
        return "DOWN";
    // numpad numeric keys handled below
    case KeyEvent.VK_MULTIPLY:
        return "MULTIPLY";
    case KeyEvent.VK_ADD:
        return "ADD";
    case KeyEvent.VK_SEPARATOR:
        return "SEPARATOR";
    case KeyEvent.VK_SUBTRACT:
        return "SUBTRACT";
    case KeyEvent.VK_DECIMAL:
        return "DECIMAL";
    case KeyEvent.VK_DIVIDE:
        return "DIVIDE";
    case KeyEvent.VK_DELETE:
        return "DELETE";
    case KeyEvent.VK_NUM_LOCK:
        return "NUM_LOCK";
    case KeyEvent.VK_SCROLL_LOCK:
        return "SCROLL_LOCK";
    case KeyEvent.VK_F1:
        return "F1";
    case KeyEvent.VK_F2:
        return "F2";
    case KeyEvent.VK_F3:
        return "F3";
    case KeyEvent.VK_F4:
        return "F4";
    case KeyEvent.VK_F5:
        return "F5";
    case KeyEvent.VK_F6:
        return "F6";
    case KeyEvent.VK_F7:
        return "F7";
    case KeyEvent.VK_F8:
        return "F8";
    case KeyEvent.VK_F9:
        return "F9";
    case KeyEvent.VK_F10:
        return "F10";
    case KeyEvent.VK_F11:
        return "F11";
    case KeyEvent.VK_F12:
        return "F12";
    case KeyEvent.VK_F13:
        return "F13";
    case KeyEvent.VK_F14:
        return "F14";
    case KeyEvent.VK_F15:
        return "F15";
    case KeyEvent.VK_F16:
        return "F16";
    case KeyEvent.VK_F17:
        return "F17";
    case KeyEvent.VK_F18:
        return "F18";
    case KeyEvent.VK_F19:
        return "F19";
    case KeyEvent.VK_F20:
        return "F20";
    case KeyEvent.VK_F21:
        return "F21";
    case KeyEvent.VK_F22:
        return "F22";
    case KeyEvent.VK_F23:
        return "F23";
    case KeyEvent.VK_F24:
        return "F24";
    case KeyEvent.VK_PRINTSCREEN:
        return "PRINTSCREEN";
    case KeyEvent.VK_INSERT:
        return "INSERT";
    case KeyEvent.VK_HELP:
        return "HELP";
    case KeyEvent.VK_META:
        return "META";
    case KeyEvent.VK_BACK_QUOTE:
        return "BACK_QUOTE";
    case KeyEvent.VK_QUOTE:
        return "QUOTE";
    case KeyEvent.VK_KP_UP:
        return "KP_UP";
    case KeyEvent.VK_KP_DOWN:
        return "KP_DOWN";
    case KeyEvent.VK_KP_LEFT:
        return "KP_LEFT";
    case KeyEvent.VK_KP_RIGHT:
        return "KP_RIGHT";
    case KeyEvent.VK_DEAD_GRAVE:
        return "DEAD_GRAVE";
    case KeyEvent.VK_DEAD_ACUTE:
        return "DEAD_ACUTE";
    case KeyEvent.VK_DEAD_CIRCUMFLEX:
        return "DEAD_CIRCUMFLEX";
    case KeyEvent.VK_DEAD_TILDE:
        return "DEAD_TILDE";
    case KeyEvent.VK_DEAD_MACRON:
        return "DEAD_MACRON";
    case KeyEvent.VK_DEAD_BREVE:
        return "DEAD_BREVE";
    case KeyEvent.VK_DEAD_ABOVEDOT:
        return "DEAD_ABOVEDOT";
    case KeyEvent.VK_DEAD_DIAERESIS:
        return "DEAD_DIAERESIS";
    case KeyEvent.VK_DEAD_ABOVERING:
        return "DEAD_ABOVERING";
    case KeyEvent.VK_DEAD_DOUBLEACUTE:
        return "DEAD_DOUBLEACUTE";
    case KeyEvent.VK_DEAD_CARON:
        return "DEAD_CARON";
    case KeyEvent.VK_DEAD_CEDILLA:
        return "DEAD_CEDILLA";
    case KeyEvent.VK_DEAD_OGONEK:
        return "DEAD_OGONEK";
    case KeyEvent.VK_DEAD_IOTA:
        return "DEAD_IOTA";
    case KeyEvent.VK_DEAD_VOICED_SOUND:
        return "DEAD_VOICED_SOUND";
    case KeyEvent.VK_DEAD_SEMIVOICED_SOUND:
        return "DEAD_SEMIVOICED_SOUND";
    case KeyEvent.VK_AMPERSAND:
        return "AMPERSAND";
    case KeyEvent.VK_ASTERISK:
        return "ASTERISK";
    case KeyEvent.VK_QUOTEDBL:
        return "QUOTEDBL";
    case KeyEvent.VK_LESS:
        return "LESS";
    case KeyEvent.VK_GREATER:
        return "GREATER";
    case KeyEvent.VK_BRACELEFT:
        return "BRACELEFT";
    case KeyEvent.VK_BRACERIGHT:
        return "BRACERIGHT";
    case KeyEvent.VK_AT:
        return "AT";
    case KeyEvent.VK_COLON:
        return "COLON";
    case KeyEvent.VK_CIRCUMFLEX:
        return "CIRCUMFLEX";
    case KeyEvent.VK_DOLLAR:
        return "DOLLAR";
    case KeyEvent.VK_EURO_SIGN:
        return "EURO_SIGN";
    case KeyEvent.VK_EXCLAMATION_MARK:
        return "EXCLAMATION_MARK";
    case KeyEvent.VK_INVERTED_EXCLAMATION_MARK:
        return "INVERTED_EXCLAMATION_MARK";
    case KeyEvent.VK_LEFT_PARENTHESIS:
        return "LEFT_PARENTHESIS";
    case KeyEvent.VK_NUMBER_SIGN:
        return "NUMBER_SIGN";
    case KeyEvent.VK_MINUS:
        return "MINUS";
    case KeyEvent.VK_PLUS:
        return "PLUS";
    case KeyEvent.VK_RIGHT_PARENTHESIS:
        return "RIGHT_PARENTHESIS";
    case KeyEvent.VK_UNDERSCORE:
        return "UNDERSCORE";
    case KeyEvent.VK_FINAL:
        return "FINAL";
    case KeyEvent.VK_CONVERT:
        return "CONVERT";
    case KeyEvent.VK_NONCONVERT:
        return "NONCONVERT";
    case KeyEvent.VK_ACCEPT:
        return "ACCEPT";
    case KeyEvent.VK_MODECHANGE:
        return "MODECHANGE";
    case KeyEvent.VK_KANA:
        return "KANA";
    case KeyEvent.VK_KANJI:
        return "KANJI";
    case KeyEvent.VK_ALPHANUMERIC:
        return "ALPHANUMERIC";
    case KeyEvent.VK_KATAKANA:
        return "KATAKANA";
    case KeyEvent.VK_HIRAGANA:
        return "HIRAGANA";
    case KeyEvent.VK_FULL_WIDTH:
        return "FULL_WIDTH";
    case KeyEvent.VK_HALF_WIDTH:
        return "HALF_WIDTH";
    case KeyEvent.VK_ROMAN_CHARACTERS:
        return "ROMAN_CHARACTERS";
    case KeyEvent.VK_ALL_CANDIDATES:
        return "ALL_CANDIDATES";
    case KeyEvent.VK_PREVIOUS_CANDIDATE:
        return "PREVIOUS_CANDIDATE";
    case KeyEvent.VK_CODE_INPUT:
        return "CODE_INPUT";
    case KeyEvent.VK_JAPANESE_KATAKANA:
        return "JAPANESE_KATAKANA";
    case KeyEvent.VK_JAPANESE_HIRAGANA:
        return "JAPANESE_HIRAGANA";
    case KeyEvent.VK_JAPANESE_ROMAN:
        return "JAPANESE_ROMAN";
    case KeyEvent.VK_KANA_LOCK:
        return "KANA_LOCK";
    case KeyEvent.VK_INPUT_METHOD_ON_OFF:
        return "INPUT_METHOD_ON_OFF";

    case KeyEvent.VK_AGAIN:
        return "AGAIN";
    case KeyEvent.VK_UNDO:
        return "UNDO";
    case KeyEvent.VK_COPY:
        return "COPY";
    case KeyEvent.VK_PASTE:
        return "PASTE";
    case KeyEvent.VK_CUT:
        return "CUT";
    case KeyEvent.VK_FIND:
        return "FIND";
    case KeyEvent.VK_PROPS:
        return "PROPS";
    case KeyEvent.VK_STOP:
        return "STOP";

    case KeyEvent.VK_COMPOSE:
        return "COMPOSE";
    case KeyEvent.VK_ALT_GRAPH:
        return "ALT_GRAPH";
    }

    if (keyCode >= KeyEvent.VK_NUMPAD0 && keyCode <= KeyEvent.VK_NUMPAD9) {
        char c = (char) (keyCode - KeyEvent.VK_NUMPAD0 + '0');
        return "NUMPAD" + c;
    }

    return "unknown(0x" + Integer.toString(keyCode, 16) + ")";
}

From source file:jdroidremote.ServerFrame.java

public static void typeCharacter(String letter) {
    System.out.println(letter);// www  .  j av  a 2 s.co  m
    Robot robot = null;
    try {
        robot = new Robot();
    } catch (Exception ex) {
        ex.printStackTrace();
    }

    if (Character.isLetter(letter.charAt(0))) {
        try {
            boolean upperCase = Character.isUpperCase(letter.charAt(0));
            String variableName = "VK_" + letter.toUpperCase();

            KeyEvent ke = new KeyEvent(new JTextField(), 0, 0, 0, 0, ' ');
            Class clazz = ke.getClass();
            Field field = clazz.getField(variableName);
            int keyCode = field.getInt(ke);

            //System.out.println(keyCode + " = keyCode");
            robot.delay(80);

            if (upperCase) {
                robot.keyPress(KeyEvent.VK_SHIFT);
            }

            robot.keyPress(keyCode);
            robot.keyRelease(keyCode);

            if (upperCase) {
                robot.keyRelease(KeyEvent.VK_SHIFT);
            }
        } catch (Exception e) {
            System.out.println(e);
        }
    } else if (letter.equals(".")) {
        robot.keyPress(KeyEvent.VK_PERIOD); //keyCode 46
        robot.keyRelease(KeyEvent.VK_PERIOD);
    } else if (letter.equals("!")) {
        robot.keyPress(KeyEvent.VK_SHIFT); //keyCode 16
        robot.keyPress(KeyEvent.VK_1); //keycode 49
        robot.keyRelease(KeyEvent.VK_1);
        robot.keyRelease(KeyEvent.VK_SHIFT);
    } else if (letter.equals(" ")) {
        robot.keyPress(KeyEvent.VK_SPACE);
        robot.keyRelease(KeyEvent.VK_SPACE);
    } else if (letter.equals("?")) {
        robot.keyPress(KeyEvent.VK_SHIFT); //keyCode 16
        robot.keyPress(KeyEvent.VK_SLASH); //keyCode 47
        robot.keyRelease(KeyEvent.VK_SLASH);
        robot.keyRelease(KeyEvent.VK_SHIFT);
    } else if (letter.equals(",")) {
        robot.keyPress(KeyEvent.VK_COMMA);
        robot.keyRelease(KeyEvent.VK_COMMA);
    } else if (letter.equals("@enter")) {
        robot.keyPress(KeyEvent.VK_ENTER);
        robot.keyRelease(KeyEvent.VK_ENTER);
    } else if (letter.equals("@backspace")) {
        robot.keyPress(KeyEvent.VK_BACK_SPACE);
        robot.keyRelease(KeyEvent.VK_BACK_SPACE);
    }
}

From source file:com.chaosting.product.hotkey.Main.java

/**
 * case ascii in (33,34,35,36,37,38,40...)shiftkeycode,keyperss(shift)keyrelease(shift)
 * //from   w w w .  ja v  a 2s .c o  m
 * String temp = "!@#$%^&()_+{}|:\"<>?";
 * String temp = "*-=[]\\;',./";
 * 
 * @param ascii
 * @return
 */
private int convertAsciiInt2KeycodeInt(int ascii) {
    if (ascii >= 65 && ascii <= 90) {
        return ascii;
    }
    if (ascii >= 48 && ascii <= 57) {
        return ascii + 48;
    }
    if (ascii >= 97 && ascii <= 122) {
        return ascii - 32;
    }
    switch (ascii) {
    case 13:
        return KeyEvent.VK_ENTER;

    case 32:
        return KeyEvent.VK_SPACE;
    //case 33:
    //   return KeyEvent.VK_EXCLAMATION_MARK;
    //case 34:
    //   return KeyEvent.VK_QUOTEDBL;
    //case 35:
    //   return KeyEvent.VK_NUMBER_SIGN;
    //case 36:
    //   return KeyEvent.VK_DOLLAR;
    // 37 %
    // 38 &
    case 39:
        return KeyEvent.VK_QUOTE;
    //case 40:
    //   return KeyEvent.VK_LEFT_PARENTHESIS;
    //case 41:
    //   return KeyEvent.VK_RIGHT_PARENTHESIS;
    case 42:
        return KeyEvent.VK_MULTIPLY;
    //case 43:
    //   return KeyEvent.VK_PLUS;
    case 44:
        return KeyEvent.VK_COMMA;
    case 45:
        return KeyEvent.VK_MINUS;
    case 46:
        return KeyEvent.VK_PERIOD;
    case 47:
        return KeyEvent.VK_SLASH;

    //case 58:
    //   return KeyEvent.VK_COLON;
    case 59:
        return KeyEvent.VK_SEMICOLON;
    //case 60:
    //   return KeyEvent.VK_LESS;
    case 61:
        return KeyEvent.VK_EQUALS;
    //case 62:
    //   return KeyEvent.VK_GREATER;
    // 63 ?   
    //case 64:
    //   return KeyEvent.VK_AT;

    case 91:
        return KeyEvent.VK_OPEN_BRACKET;
    case 92:
        return KeyEvent.VK_BACK_SLASH;
    case 93:
        return KeyEvent.VK_CLOSE_BRACKET;
    //case 94:
    //   return KeyEvent.VK_CIRCUMFLEX;
    //case 95:
    //   return KeyEvent.VK_UNDERSCORE;
    // 96 `
    //case 123:
    //   return KeyEvent.VK_BRACELEFT;
    // 124 |   
    //case 125:
    //   return KeyEvent.VK_BRACERIGHT;
    // 126 ~   
    default:
        return -1;
    }
}

From source file:com.digitalgeneralists.assurance.ui.MainWindow.java

private void initializeComponent() {
    if (!this.initialized) {
        logger.info("Initializing the main window.");

        if (AssuranceUtils.getPlatform() == Platform.MAC) {

            System.setProperty("apple.laf.useScreenMenuBar", "true");
            com.apple.eawt.Application macApplication = com.apple.eawt.Application.getApplication();
            MacApplicationAdapter macAdapter = new MacApplicationAdapter(this);
            macApplication.addApplicationListener(macAdapter);
            macApplication.setEnabledPreferencesMenu(true);
        }//w w w  .  j a v  a  2  s .  c o  m

        this.setTitle(Application.applicationShortName);

        this.setDefaultCloseOperation(EXIT_ON_CLOSE);

        GridBagLayout gridbag = new GridBagLayout();
        this.setLayout(gridbag);

        this.topArea = new JTabbedPane();

        this.scanLaunchPanel.setPreferredSize(new Dimension(600, 150));

        this.scanHistoryPanel.setPreferredSize(new Dimension(600, 150));

        this.topArea.addTab("Scan", this.scanLaunchPanel);

        this.topArea.addTab("History", this.scanHistoryPanel);

        this.resultsPanel.setPreferredSize(new Dimension(600, 400));

        this.topArea.addChangeListener(new ChangeListener() {
            public void stateChanged(ChangeEvent e) {
                resultsPanel.resetPanel();
                // NOTE:  This isn't ideal.  It feels brittle.
                if (topArea.getSelectedIndex() == viewHistoryMenuItemIndex) {
                    viewHistoryMenuItem.setSelected(true);
                } else {
                    viewScanMenuItem.setSelected(true);
                }
            }
        });

        GridBagConstraints topPanelConstraints = new GridBagConstraints();
        topPanelConstraints.anchor = GridBagConstraints.NORTH;
        topPanelConstraints.fill = GridBagConstraints.BOTH;
        topPanelConstraints.gridx = 0;
        topPanelConstraints.gridy = 0;
        topPanelConstraints.weightx = 1.0;
        topPanelConstraints.weighty = 0.33;
        topPanelConstraints.gridheight = 1;
        topPanelConstraints.gridwidth = 1;
        topPanelConstraints.insets = new Insets(0, 0, 0, 0);

        this.getContentPane().add(this.topArea, topPanelConstraints);

        GridBagConstraints resultsPanelConstraints = new GridBagConstraints();
        resultsPanelConstraints.anchor = GridBagConstraints.SOUTH;
        resultsPanelConstraints.fill = GridBagConstraints.BOTH;
        resultsPanelConstraints.gridx = 0;
        resultsPanelConstraints.gridy = 1;
        resultsPanelConstraints.weightx = 1.0;
        resultsPanelConstraints.weighty = 0.67;
        resultsPanelConstraints.gridheight = 1;
        resultsPanelConstraints.gridwidth = 1;
        resultsPanelConstraints.insets = new Insets(0, 0, 0, 0);

        this.getContentPane().add(this.resultsPanel, resultsPanelConstraints);

        this.applicationDelegate.addEventObserver(ScanStartedEvent.class, this);
        this.applicationDelegate.addEventObserver(ScanCompletedEvent.class, this);
        this.applicationDelegate.addEventObserver(SetScanDefinitionMenuStateEvent.class, this);
        this.applicationDelegate.addEventObserver(SetScanResultsMenuStateEvent.class, this);
        this.applicationDelegate.addEventObserver(ApplicationConfigurationLoadedEvent.class, this);

        JMenu menu;
        JMenuItem menuItem;

        menuBar = new JMenuBar();

        StringBuilder accessiblityLabel = new StringBuilder(128);
        if (AssuranceUtils.getPlatform() != Platform.MAC) {
            menu = new JMenu(Application.applicationShortName);
            menu.getAccessibleContext().setAccessibleDescription(accessiblityLabel.append("Actions for ")
                    .append(Application.applicationShortName).append(" application").toString());
            accessiblityLabel.setLength(0);
            menuBar.add(menu);

            menuItem = new JMenuItem(MainWindow.quitApplicationMenuLabel, KeyEvent.VK_Q);
            menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
            menuItem.getAccessibleContext().setAccessibleDescription(accessiblityLabel.append("Close the ")
                    .append(Application.applicationShortName).append(" application").toString());
            accessiblityLabel.setLength(0);
            menuItem.addActionListener(this);
            menuItem.setActionCommand(AssuranceActions.quitApplicationAction);
            menu.add(menuItem);

            menu.addSeparator();

            menuItem = new JMenuItem(MainWindow.aboutApplicationMenuLabel);
            menuItem.getAccessibleContext().setAccessibleDescription(
                    accessiblityLabel.append("Display information about this version of ")
                            .append(Application.applicationShortName).append(".").toString());
            accessiblityLabel.setLength(0);
            menuItem.addActionListener(this);
            menuItem.setActionCommand(AssuranceActions.aboutApplicationAction);
            menu.add(menuItem);
        }

        menu = new JMenu("Scan");
        menu.setMnemonic(KeyEvent.VK_S);
        menu.getAccessibleContext().setAccessibleDescription("Actions for file scans");
        menuBar.add(menu);

        menuItem = new JMenuItem(MainWindow.newScanDefinitonMenuLabel, KeyEvent.VK_N);
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK));
        menuItem.getAccessibleContext().setAccessibleDescription("Create a new scan definition");
        menuItem.addActionListener(this.scanLaunchPanel);
        menuItem.setActionCommand(AssuranceActions.newScanDefinitonAction);
        menu.add(menuItem);

        menuItem = new JMenuItem(MainWindow.deleteScanDefinitonMenuLabel, KeyEvent.VK_D);
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, ActionEvent.CTRL_MASK));
        menuItem.getAccessibleContext().setAccessibleDescription("Delete the selected scan definition");
        menuItem.addActionListener(this.scanLaunchPanel);
        menuItem.setActionCommand(AssuranceActions.deleteScanDefinitonAction);
        menu.add(menuItem);

        menu.addSeparator();

        menuItem = new JMenuItem(MainWindow.scanMenuLabel, KeyEvent.VK_S);
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
        menuItem.getAccessibleContext()
                .setAccessibleDescription("Launch a scan using the selected scan definition");
        menuItem.addActionListener(this.scanLaunchPanel);
        menuItem.setActionCommand(AssuranceActions.scanAction);
        menu.add(menuItem);

        menuItem = new JMenuItem(MainWindow.scanAndMergeMenuLabel, KeyEvent.VK_M);
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, ActionEvent.CTRL_MASK));
        menuItem.getAccessibleContext().setAccessibleDescription(
                "Launch a scan using the selected scan definition and merge the results");
        menuItem.addActionListener(this.scanLaunchPanel);
        menuItem.setActionCommand(AssuranceActions.scanAndMergeAction);
        menu.add(menuItem);

        menu = new JMenu("Results");
        menu.setMnemonic(KeyEvent.VK_R);
        menu.getAccessibleContext().setAccessibleDescription("Actions for scan results");
        menuBar.add(menu);

        menuItem = new JMenuItem(MainWindow.replaceSourceMenuLabel, KeyEvent.VK_O);
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));
        menuItem.getAccessibleContext()
                .setAccessibleDescription("Replace the source file with the target file");
        menuItem.addActionListener(this.resultsPanel.getResultMenuListener());
        menuItem.setActionCommand(AssuranceActions.replaceSourceAction);
        menu.add(menuItem);

        menuItem = new JMenuItem(MainWindow.replaceTargetMenuLabel, KeyEvent.VK_T);
        menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, ActionEvent.CTRL_MASK));
        menuItem.getAccessibleContext()
                .setAccessibleDescription("Replace the target file with the source file");
        menuItem.addActionListener(this.resultsPanel.getResultMenuListener());
        menuItem.setActionCommand(AssuranceActions.replaceTargetAction);
        menu.add(menuItem);

        menu.addSeparator();

        menuItem = new JMenuItem(MainWindow.sourceAttributesMenuLabel);
        menuItem.getAccessibleContext().setAccessibleDescription("View the source file attributes");
        menuItem.addActionListener(this.resultsPanel.getResultMenuListener());
        menuItem.setActionCommand(AssuranceActions.sourceAttributesAction);
        menu.add(menuItem);

        menuItem = new JMenuItem(MainWindow.targetAttributesMenuLabel);
        menuItem.getAccessibleContext().setAccessibleDescription("View the target file attributes");
        menuItem.addActionListener(this.resultsPanel.getResultMenuListener());
        menuItem.setActionCommand(AssuranceActions.targetAttributesAction);
        menu.add(menuItem);

        menu = new JMenu("View");
        menu.setMnemonic(KeyEvent.VK_V);
        menu.getAccessibleContext().setAccessibleDescription(
                accessiblityLabel.append("Views within ").append(Application.applicationShortName).toString());
        accessiblityLabel.setLength(0);
        menuBar.add(menu);

        ButtonGroup group = new ButtonGroup();

        this.viewScanMenuItem = new JRadioButtonMenuItem(MainWindow.viewScanMenuLabel);
        this.viewScanMenuItem.addActionListener(this);
        this.viewScanMenuItem.setActionCommand(AssuranceActions.viewScanAction);
        this.viewScanMenuItem.setSelected(true);
        group.add(this.viewScanMenuItem);
        menu.add(this.viewScanMenuItem);

        this.viewHistoryMenuItem = new JRadioButtonMenuItem(MainWindow.viewHistoryMenuLabel);
        this.viewHistoryMenuItem.addActionListener(this);
        this.viewHistoryMenuItem.setActionCommand(AssuranceActions.viewHistoryAction);
        this.viewHistoryMenuItem.setSelected(true);
        group.add(this.viewHistoryMenuItem);
        menu.add(this.viewHistoryMenuItem);

        if (AssuranceUtils.getPlatform() != Platform.MAC) {
            menu = new JMenu("Tools");
            menu.getAccessibleContext()
                    .setAccessibleDescription(accessiblityLabel.append("Additional actions for ")
                            .append(Application.applicationShortName).append(" application").toString());
            accessiblityLabel.setLength(0);
            menuBar.add(menu);

            menuItem = new JMenuItem(MainWindow.settingsMenuLabel, KeyEvent.VK_COMMA);
            menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_COMMA, ActionEvent.CTRL_MASK));
            menuItem.getAccessibleContext()
                    .setAccessibleDescription(accessiblityLabel.append("Change settings for the ")
                            .append(Application.applicationShortName).append(" application").toString());
            accessiblityLabel.setLength(0);
            menuItem.addActionListener(this);
            menuItem.setActionCommand(AssuranceActions.displaySettingsAction);
            menu.add(menuItem);
        }

        this.setJMenuBar(menuBar);

        this.initialized = true;
    }
}

From source file:me.solhub.simple.engine.DebugLocationsStructure.java

/**
 * Switches the color of the agent from destination to group or vice versa
 * whenever the space bar is pressed/*from   w  ww.  j  a  v  a2s.  c om*/
 */
private void handleColorSwitchingInput() {
    if (_input.isKeyDown(KeyEvent.VK_SPACE) && inputDelayCount > inputDelay) {
        isDestinationColors = !isDestinationColors;
        inputDelayCount = 0;
    }
    if (_input.isKeyDown(KeyEvent.VK_PERIOD)) {
        LIVE_DELAY += 1;
        if (LIVE_DELAY < 0) {
            LIVE_DELAY = 0;
        }
    }
    if (_input.isKeyDown(KeyEvent.VK_COMMA)) {
        LIVE_DELAY -= 1;
        if (LIVE_DELAY < 0) {
            LIVE_DELAY = 0;
        }
    }
    if (_input.isKeyDown(KeyEvent.VK_UP)) {
        _yOffset += 1;
    }
    if (_input.isKeyDown(KeyEvent.VK_DOWN)) {
        _yOffset -= 1;
    }
    if (_input.isKeyDown(KeyEvent.VK_RIGHT)) {
        _xOffset -= 1;
    }
    if (_input.isKeyDown(KeyEvent.VK_LEFT)) {
        _xOffset += 1;
    }
    if (_input.isKeyDown(KeyEvent.VK_ENTER)) {
        while (!_input.isKeyDown(KeyEvent.VK_SHIFT)) {
            //this makes it work, without this line it will not work as desired
            //                System.out.println(_input.isKeyDown( KeyEvent.VK_ENTER ));
            draw();
            handleColorSwitchingInput();
        }
    }
    inputDelayCount++;
}

From source file:plugins.tprovoost.Microscopy.MicroManagerForIcy.MMMainFrame.java

/**
 * Singleton pattern : private constructor Use instead.
 *//*w  w w  .j av a  2  s . c o m*/
private MMMainFrame() {
    super(NODE_NAME, false, true, false, true);
    instancing = true;
    // --------------
    // INITIALIZATION
    // --------------
    _sysConfigFile = "";
    _isConfigLoaded = false;
    _root = PluginPreferences.getPreferences().node(NODE_NAME);
    final MainFrame mainFrame = Icy.getMainInterface().getMainFrame();

    // --------------
    // PROGRESS FRAME
    // --------------
    ThreadUtil.invokeLater(new Runnable() {
        @Override
        public void run() {
            _progressFrame = new IcyFrame("", false, false, false, false);
            _progressBar = new JProgressBar();
            _progressBar.setString("Please wait while loading...");
            _progressBar.setStringPainted(true);
            _progressBar.setIndeterminate(true);
            _progressBar.setMinimum(0);
            _progressBar.setMaximum(1000);
            _progressBar.setBounds(50, 50, 100, 30);
            _progressFrame.setSize(300, 100);
            _progressFrame.setResizable(false);
            _progressFrame.add(_progressBar);
            _progressFrame.addToMainDesktopPane();
            loadConfig(true);
            if (_sysConfigFile == "") {
                instancing = false;
                return;
            }
            ThreadUtil.bgRun(new Runnable() {

                @Override
                public void run() {
                    while (!_isConfigLoaded) {
                        if (!instancing)
                            return;
                        try {
                            Thread.sleep(10);
                        } catch (InterruptedException e) {
                        }
                    }
                    ThreadUtil.invokeLater(new Runnable() {

                        @Override
                        public void run() {
                            // --------------------
                            // START INITIALIZATION
                            // --------------------
                            if (_progressBar != null)
                                getContentPane().remove(_progressBar);
                            if (mCore == null) {
                                close();
                                return;
                            }

                            // ReportingUtils.setCore(mCore);
                            _afMgr = new AutofocusManager(MMMainFrame.this);
                            acqMgr = new AcquisitionManager();
                            PositionList posList = new PositionList();

                            _camera_label = MMCoreJ.getG_Keyword_CameraName();
                            if (_camera_label == null)
                                _camera_label = "";
                            try {
                                setPositionList(posList);
                            } catch (MMScriptException e1) {
                                e1.printStackTrace();
                            }
                            posListDlg_ = new PositionListDlg(mCore, MMMainFrame.this, _posList, null, dlg);
                            posListDlg_.setModalityType(ModalityType.APPLICATION_MODAL);

                            callback = new EventCallBackManager();
                            mCore.registerCallback(callback);

                            engine_ = new AcquisitionWrapperEngineIcy();
                            engine_.setParentGUI(MMMainFrame.this);
                            engine_.setCore(mCore, getAutofocusManager());
                            engine_.setPositionList(getPositionList());

                            setSystemMenuCallback(new MenuCallback() {

                                @Override
                                public JMenu getMenu() {
                                    JMenu toReturn = MMMainFrame.this.getDefaultSystemMenu();
                                    JMenuItem hconfig = new JMenuItem("Configuration Wizard");
                                    hconfig.setIcon(new IcyIcon("cog", MENU_ICON_SIZE));

                                    hconfig.addActionListener(new ActionListener() {

                                        @Override
                                        public void actionPerformed(ActionEvent e) {
                                            if (!_pluginListEmpty && !ConfirmDialog.confirm("Are you sure ?",
                                                    "<html>Loading the Configuration Wizard will unload all the devices and pause all running acquisitions.</br> Are you sure you want to continue ?</html>"))
                                                return;
                                            notifyConfigAboutToChange(null);
                                            try {
                                                mCore.unloadAllDevices();
                                            } catch (Exception e1) {
                                                e1.printStackTrace();
                                            }
                                            String previous_config = _sysConfigFile;
                                            ConfiguratorDlg2 configurator = new ConfiguratorDlg2(mCore,
                                                    _sysConfigFile);
                                            configurator.setVisible(true);
                                            String res = configurator.getFileName();
                                            if (_sysConfigFile == "" || _sysConfigFile == res || res == "") {
                                                _sysConfigFile = previous_config;
                                                loadConfig();
                                            }
                                            refreshGUI();
                                            notifyConfigChanged(null);
                                        }
                                    });

                                    JMenuItem menuPxSizeConfigItem = new JMenuItem("Pixel Size Config");
                                    menuPxSizeConfigItem.setIcon(new IcyIcon("link", MENU_ICON_SIZE));
                                    menuPxSizeConfigItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_G,
                                            InputEvent.SHIFT_DOWN_MASK | SHORTCUTKEY_MASK));
                                    menuPxSizeConfigItem.addActionListener(new ActionListener() {

                                        @Override
                                        public void actionPerformed(ActionEvent e) {
                                            CalibrationListDlg dlg = new CalibrationListDlg(mCore);
                                            dlg.setDefaultCloseOperation(2);
                                            dlg.setParentGUI(MMMainFrame.this);
                                            dlg.setVisible(true);
                                            dlg.addWindowListener(new WindowAdapter() {
                                                @Override
                                                public void windowClosed(WindowEvent e) {
                                                    super.windowClosed(e);
                                                    notifyConfigChanged(null);
                                                }
                                            });
                                            notifyConfigAboutToChange(null);
                                        }
                                    });

                                    JMenuItem loadConfigItem = new JMenuItem("Load Configuration");
                                    loadConfigItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,
                                            InputEvent.SHIFT_DOWN_MASK | SHORTCUTKEY_MASK));
                                    loadConfigItem.setIcon(new IcyIcon("folder_open", MENU_ICON_SIZE));
                                    loadConfigItem.addActionListener(new ActionListener() {

                                        @Override
                                        public void actionPerformed(ActionEvent e) {
                                            loadConfig();
                                            initializeGUI();
                                            refreshGUI();
                                        }
                                    });
                                    JMenuItem saveConfigItem = new JMenuItem("Save Configuration");
                                    saveConfigItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,
                                            InputEvent.SHIFT_DOWN_MASK | SHORTCUTKEY_MASK));
                                    saveConfigItem.setIcon(new IcyIcon("save", MENU_ICON_SIZE));
                                    saveConfigItem.addActionListener(new ActionListener() {

                                        @Override
                                        public void actionPerformed(ActionEvent e) {
                                            saveConfig();
                                        }
                                    });
                                    JMenuItem advancedConfigItem = new JMenuItem("Advanced Configuration");
                                    advancedConfigItem.setIcon(new IcyIcon("wrench_plus", MENU_ICON_SIZE));
                                    advancedConfigItem.addActionListener(new ActionListener() {

                                        /**
                                         */
                                        @Override
                                        public void actionPerformed(ActionEvent e) {
                                            new ToolTipFrame(
                                                    "<html><h3>About Advanced Config</h3><p>Advanced Configuration is a tool "
                                                            + "in which you fill some data <br/>about your configuration that some "
                                                            + "plugins may need to access to.<br/> Exemple: the real values of the magnification"
                                                            + "of your objectives.</p></html>",
                                                    "MM4IcyAdvancedConfig");
                                            if (advancedDlg == null)
                                                advancedDlg = new AdvancedConfigurationDialog();
                                            advancedDlg.setVisible(!advancedDlg.isVisible());
                                            advancedDlg.setLocationRelativeTo(mainFrame);
                                        }
                                    });
                                    JMenuItem loadPresetConfigItem = new JMenuItem(
                                            "Load Configuration Presets");
                                    loadPresetConfigItem.setIcon(new IcyIcon("doc_import", MENU_ICON_SIZE));
                                    loadPresetConfigItem.addActionListener(new ActionListener() {

                                        @Override
                                        public void actionPerformed(ActionEvent e) {
                                            notifyConfigAboutToChange(null);
                                            loadPresets();
                                            notifyConfigChanged(null);
                                        }
                                    });
                                    JMenuItem savePresetConfigItem = new JMenuItem(
                                            "Save Configuration Presets");
                                    savePresetConfigItem.setIcon(new IcyIcon("doc_export", MENU_ICON_SIZE));
                                    savePresetConfigItem.addActionListener(new ActionListener() {

                                        @Override
                                        public void actionPerformed(ActionEvent e) {
                                            savePresets();
                                        }
                                    });
                                    JMenuItem aboutItem = new JMenuItem("About");
                                    aboutItem.setIcon(new IcyIcon("info", MENU_ICON_SIZE));
                                    aboutItem.addActionListener(new ActionListener() {

                                        @Override
                                        public void actionPerformed(ActionEvent e) {
                                            final JDialog dialog = new JDialog(mainFrame, "About");
                                            JPanel panel_container = new JPanel();
                                            panel_container
                                                    .setBorder(BorderFactory.createEmptyBorder(10, 20, 10, 20));
                                            JPanel center = new JPanel(new BorderLayout());
                                            final JLabel value = new JLabel("<html><body>"
                                                    + "<h2>About</h2><p>Micro-Manager for Icy is being developed by Thomas Provoost."
                                                    + "<br/>Copyright 2011, Institut Pasteur</p><br/>"
                                                    + "<p>This plugin is based on Micro-Manager v1.4.6. which is developed under the following license:<br/>"
                                                    + "<i>This software is distributed free of charge in the hope that it will be<br/>"
                                                    + "useful, but WITHOUT ANY WARRANTY; without even the implied<br/>"
                                                    + "warranty of merchantability or fitness for a particular purpose. In no<br/>"
                                                    + "event shall the copyright owner or contributors be liable for any direct,<br/>"
                                                    + "indirect, incidental spacial, examplary, or consequential damages.<br/>"
                                                    + "Copyright University of California San Francisco, 2007, 2008, 2009,<br/>"
                                                    + "2010. All rights reserved.</i>" + "</p>"
                                                    + "</body></html>");
                                            JLabel link = new JLabel(
                                                    "<html><a href=\"\">For more information, please follow this link.</a></html>");
                                            link.addMouseListener(new MouseAdapter() {
                                                @Override
                                                public void mousePressed(MouseEvent mouseevent) {
                                                    NetworkUtil.openBrowser(
                                                            "http://valelab.ucsf.edu/~MM/MMwiki/index.php/Micro-Manager");
                                                }
                                            });
                                            value.setSize(new Dimension(50, 18));
                                            value.setAlignmentX(SwingConstants.HORIZONTAL);
                                            value.setBorder(BorderFactory.createEmptyBorder(0, 0, 20, 0));

                                            center.add(value, BorderLayout.CENTER);
                                            center.add(link, BorderLayout.SOUTH);

                                            JPanel panel_south = new JPanel();
                                            panel_south.setLayout(new BoxLayout(panel_south, BoxLayout.X_AXIS));
                                            JButton btn = new JButton("OK");
                                            btn.addActionListener(new ActionListener() {

                                                @Override
                                                public void actionPerformed(ActionEvent actionevent) {
                                                    dialog.dispose();
                                                }
                                            });
                                            panel_south.add(Box.createHorizontalGlue());
                                            panel_south.add(btn);
                                            panel_south.add(Box.createHorizontalGlue());

                                            dialog.setLayout(new BorderLayout());
                                            panel_container.setLayout(new BorderLayout());
                                            panel_container.add(center, BorderLayout.CENTER);
                                            panel_container.add(panel_south, BorderLayout.SOUTH);
                                            dialog.add(panel_container, BorderLayout.CENTER);
                                            dialog.setResizable(false);
                                            dialog.setVisible(true);
                                            dialog.pack();
                                            dialog.setLocation(
                                                    (int) mainFrame.getSize().getWidth() / 2
                                                            - dialog.getWidth() / 2,
                                                    (int) mainFrame.getSize().getHeight() / 2
                                                            - dialog.getHeight() / 2);
                                            dialog.setLocationRelativeTo(mainFrame);
                                        }
                                    });
                                    JMenuItem propertyBrowserItem = new JMenuItem("Property Browser");
                                    propertyBrowserItem.setAccelerator(
                                            KeyStroke.getKeyStroke(KeyEvent.VK_COMMA, SHORTCUTKEY_MASK));
                                    propertyBrowserItem.setIcon(new IcyIcon("db", MENU_ICON_SIZE));
                                    propertyBrowserItem.addActionListener(new ActionListener() {

                                        @Override
                                        public void actionPerformed(ActionEvent e) {
                                            editor.setVisible(!editor.isVisible());
                                        }
                                    });
                                    int idx = 0;
                                    toReturn.insert(hconfig, idx++);
                                    toReturn.insert(loadConfigItem, idx++);
                                    toReturn.insert(saveConfigItem, idx++);
                                    toReturn.insert(advancedConfigItem, idx++);
                                    toReturn.insertSeparator(idx++);
                                    toReturn.insert(loadPresetConfigItem, idx++);
                                    toReturn.insert(savePresetConfigItem, idx++);
                                    toReturn.insertSeparator(idx++);
                                    toReturn.insert(propertyBrowserItem, idx++);
                                    toReturn.insert(menuPxSizeConfigItem, idx++);
                                    toReturn.insertSeparator(idx++);
                                    toReturn.insert(aboutItem, idx++);
                                    return toReturn;
                                }
                            });

                            saveConfigButton_ = new JButton("Save Button");

                            // SETUP
                            _groupPad = new ConfigGroupPad();
                            _groupPad.setParentGUI(MMMainFrame.this);
                            _groupPad.setFont(new Font("", 0, 10));
                            _groupPad.setCore(mCore);
                            _groupPad.setParentGUI(MMMainFrame.this);
                            _groupButtonsPanel = new ConfigButtonsPanel();
                            _groupButtonsPanel.setCore(mCore);
                            _groupButtonsPanel.setGUI(MMMainFrame.this);
                            _groupButtonsPanel.setConfigPad(_groupPad);

                            // LEFT PART OF INTERFACE
                            _panelConfig = new JPanel();
                            _panelConfig.setLayout(new BoxLayout(_panelConfig, BoxLayout.Y_AXIS));
                            _panelConfig.add(_groupPad, BorderLayout.CENTER);
                            _panelConfig.add(_groupButtonsPanel, BorderLayout.SOUTH);
                            _panelConfig.setPreferredSize(new Dimension(300, 300));

                            // MIDDLE PART OF INTERFACE
                            _panel_cameraSettings = new JPanel();
                            _panel_cameraSettings.setLayout(new GridLayout(5, 2));
                            _panel_cameraSettings.setMinimumSize(new Dimension(100, 200));

                            _txtExposure = new JTextField();
                            try {
                                mCore.setExposure(90.0D);
                                _txtExposure.setText(String.valueOf(mCore.getExposure()));
                            } catch (Exception e2) {
                                _txtExposure.setText("90");
                            }
                            _txtExposure.setMaximumSize(new Dimension(Integer.MAX_VALUE, 20));
                            _txtExposure.addKeyListener(new KeyAdapter() {
                                @Override
                                public void keyPressed(KeyEvent keyevent) {
                                    if (keyevent.getKeyCode() == KeyEvent.VK_ENTER)
                                        setExposure();
                                }
                            });
                            _panel_cameraSettings.add(new JLabel("Exposure [ms]: "));
                            _panel_cameraSettings.add(_txtExposure);

                            _combo_binning = new JComboBox();
                            _combo_binning.setMaximumRowCount(4);
                            _combo_binning.setMaximumSize(new Dimension(Integer.MAX_VALUE, 25));
                            _combo_binning.addActionListener(new ActionListener() {
                                public void actionPerformed(ActionEvent e) {
                                    changeBinning();
                                }
                            });

                            _panel_cameraSettings.add(new JLabel("Binning: "));
                            _panel_cameraSettings.add(_combo_binning);

                            _combo_shutters = new JComboBox();
                            _combo_shutters.addActionListener(new ActionListener() {
                                public void actionPerformed(ActionEvent arg0) {
                                    try {
                                        if (_combo_shutters.getSelectedItem() != null) {
                                            mCore.setShutterDevice((String) _combo_shutters.getSelectedItem());
                                            _prefs.put(PREF_SHUTTER, (String) _combo_shutters
                                                    .getItemAt(_combo_shutters.getSelectedIndex()));
                                        }
                                    } catch (Exception e) {
                                        e.printStackTrace();
                                    }
                                }
                            });
                            _combo_shutters.setMaximumSize(new Dimension(Integer.MAX_VALUE, 25));
                            _panel_cameraSettings.add(new JLabel("Shutter : "));
                            _panel_cameraSettings.add(_combo_shutters);

                            ActionListener action_listener = new ActionListener() {
                                @Override
                                public void actionPerformed(ActionEvent e) {
                                    updateHistogram();
                                }
                            };

                            _cbAbsoluteHisto = new JCheckBox();
                            _cbAbsoluteHisto.addActionListener(action_listener);
                            _cbAbsoluteHisto.addActionListener(new ActionListener() {
                                @Override
                                public void actionPerformed(ActionEvent actionevent) {
                                    _comboBitDepth.setEnabled(_cbAbsoluteHisto.isSelected());
                                    _prefs.putBoolean(PREF_ABS_HIST, _cbAbsoluteHisto.isSelected());
                                }
                            });
                            _panel_cameraSettings.add(new JLabel("Display absolute histogram ?"));
                            _panel_cameraSettings.add(_cbAbsoluteHisto);

                            _comboBitDepth = new JComboBox(new String[] { "8-bit", "9-bit", "10-bit", "11-bit",
                                    "12-bit", "13-bit", "14-bit", "15-bit", "16-bit" });
                            _comboBitDepth.addActionListener(action_listener);
                            _comboBitDepth.addActionListener(new ActionListener() {
                                @Override
                                public void actionPerformed(ActionEvent actionevent) {
                                    _prefs.putInt(PREF_BITDEPTH, _comboBitDepth.getSelectedIndex());
                                }
                            });
                            _comboBitDepth.setMaximumSize(new Dimension(Integer.MAX_VALUE, 20));
                            _comboBitDepth.setEnabled(false);
                            _panel_cameraSettings.add(new JLabel("Select your bit depth for abs. hitogram: "));
                            _panel_cameraSettings.add(_comboBitDepth);

                            // Acquisition
                            _panelAcquisitions = new JPanel();
                            _panelAcquisitions.setLayout(new BoxLayout(_panelAcquisitions, BoxLayout.Y_AXIS));

                            // Color settings
                            _panelColorChooser = new JPanel();
                            _panelColorChooser.setLayout(new BoxLayout(_panelColorChooser, BoxLayout.Y_AXIS));
                            painterPreferences = MicroscopePainterPreferences.getInstance();
                            painterPreferences.setPreferences(_prefs.node("paintersPreferences"));
                            painterPreferences.loadColors();

                            HashMap<String, Color> allColors = painterPreferences.getColors();
                            String[] allKeys = (String[]) allColors.keySet().toArray(new String[0]);
                            String[] columnNames = { "Painter", "Color", "Transparency" };
                            Object[][] data = new Object[allKeys.length][3];

                            for (int i = 0; i < allKeys.length; ++i) {
                                final int actualRow = i;
                                String actualKey = allKeys[i].toString();
                                data[i][0] = actualKey;
                                data[i][1] = allColors.get(actualKey);
                                final JSlider slider = new JSlider(0, 255, allColors.get(actualKey).getAlpha());
                                slider.addChangeListener(new ChangeListener() {

                                    @Override
                                    public void stateChanged(ChangeEvent changeevent) {
                                        painterTable.setValueAt(slider, actualRow, 2);
                                    }
                                });
                                data[i][2] = slider;
                            }
                            final AbstractTableModel tableModel = new JTableEvolvedModel(columnNames, data);
                            painterTable = new JTable(tableModel);
                            painterTable.getModel().addTableModelListener(new TableModelListener() {

                                @Override
                                public void tableChanged(TableModelEvent tablemodelevent) {
                                    if (tablemodelevent.getType() == TableModelEvent.UPDATE) {
                                        int row = tablemodelevent.getFirstRow();
                                        int col = tablemodelevent.getColumn();
                                        String columnName = tableModel.getColumnName(col);
                                        String painterName = (String) tableModel.getValueAt(row, 0);
                                        if (columnName.contains("Color")) {
                                            // New color value
                                            int alpha = painterPreferences.getColor(painterName).getAlpha();
                                            Color coloNew = (Color) tableModel.getValueAt(row, 1);
                                            painterPreferences.setColor(painterName, new Color(coloNew.getRed(),
                                                    coloNew.getGreen(), coloNew.getBlue(), alpha));
                                        } else if (columnName.contains("Transparency")) {
                                            // New alpha value
                                            Color c = painterPreferences.getColor(painterName);
                                            int alphaValue = ((JSlider) tableModel.getValueAt(row, 2))
                                                    .getValue();
                                            painterPreferences.setColor(painterName, new Color(c.getRed(),
                                                    c.getGreen(), c.getBlue(), alphaValue));
                                        }
                                        /*
                                         * for (int i = 0; i <
                                         * tableModel.getRowCount(); ++i) { try {
                                         * String painterName = (String)
                                         * tableModel.getValueAt(i, 0); Color c =
                                         * (Color) tableModel.getValueAt(i, 1); int
                                         * alphaValue; if (ASpinnerChanged &&
                                         * tablemodelevent.getFirstRow() == i) {
                                         * alphaValue = ((JSlider)
                                         * tableModel.getValueAt(i, 2)).getValue();
                                         * } else { alphaValue =
                                         * painterPreferences.getColor
                                         * (painterPreferences
                                         * .getPainterName(i)).getAlpha(); }
                                         * painterPreferences.setColor(painterName,
                                         * new Color(c.getRed(), c.getGreen(),
                                         * c.getBlue(), alphaValue)); } catch
                                         * (Exception e) { System.out.println(
                                         * "error with painter table update"); } }
                                         */
                                    }
                                }
                            });
                            painterTable.setPreferredScrollableViewportSize(new Dimension(500, 70));
                            painterTable.setFillsViewportHeight(true);

                            // Create the scroll pane and add the table to it.
                            JScrollPane scrollPane = new JScrollPane(painterTable);

                            // Set up renderer and editor for the Favorite Color
                            // column.
                            painterTable.setDefaultRenderer(Color.class, new ColorRenderer(true));
                            painterTable.setDefaultEditor(Color.class, new ColorEditor());

                            painterTable.setDefaultRenderer(JSlider.class, new SliderRenderer(0, 255));
                            painterTable.setDefaultEditor(JSlider.class, new SliderEditor());

                            _panelColorChooser.add(scrollPane);
                            _panelColorChooser.add(Box.createVerticalGlue());

                            _mainPanel = new JPanel();
                            _mainPanel.setLayout(new BorderLayout());

                            // EDITOR
                            // will refresh the data and verify if any change
                            // occurs.
                            // editor = new PropertyEditor(MMMainFrame.this);
                            // editor.setCore(mCore);
                            // editor.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
                            // editor.addToMainDesktopPane();
                            // editor.refresh();
                            // editor.start();

                            editor = new PropertyEditor();
                            editor.setGui(MMMainFrame.this);
                            editor.setCore(mCore);
                            editor.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
                            // editor.addToMainDesktopPane();
                            // editor.refresh();
                            // editor.start();

                            add(_mainPanel);
                            initializeGUI();
                            loadPreferences();
                            refreshGUI();
                            setResizable(true);
                            addToMainDesktopPane();
                            instanced = true;
                            instancing = false;
                            _singleton = MMMainFrame.this;
                            setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
                            addFrameListener(new IcyFrameAdapter() {
                                @Override
                                public void icyFrameClosing(IcyFrameEvent e) {
                                    customClose();
                                }
                            });
                            acceptListener = new AcceptListener() {

                                @Override
                                public boolean accept(Object source) {
                                    close();
                                    return _pluginListEmpty;
                                }
                            };

                            adapter = new MainAdapter() {

                                @Override
                                public void sequenceOpened(MainEvent event) {
                                    updateHistogram();
                                }

                            };
                            Icy.getMainInterface().addCanExitListener(acceptListener);
                            Icy.getMainInterface().addListener(adapter);
                        }
                    });
                }
            });
        }
    });
}

From source file:com.projity.pm.graphic.frames.GraphicManager.java

public void setToolBarAndMenus(final Container contentPane) {
    JToolBar toolBar;/*from w  w w  . ja  v a  2 s  .c o m*/
    if (Environment.isRibbonUI()) {
        if (Environment.isNeedToRestart()) {
            contentPane.add(new JLabel(Messages.getString("Error.restart")), BorderLayout.CENTER);
            return;
        }

        setRibbon((JRibbonFrame) container, getMenuManager());

        //         JToolBar viewToolBar = getMenuManager().getToolBar(MenuManager.VIEW_TOOL_BAR_WITH_NO_SUB_VIEW_OPTION);
        //         topTabs = new TabbedNavigation();
        //         JComponent tabs = topTabs.createContentPanel(getMenuManager(),viewToolBar,0,JTabbedPane.TOP,true);
        //         tabs.setAlignmentX(0.0f); // so it is left justified
        //
        //
        //          Box top = new Box(BoxLayout.Y_AXIS);
        //          JComponent bottom;
        //         top.add(tabs);
        //         bottom = new TabbedNavigation().createContentPanel(getMenuManager(),viewToolBar,1,JTabbedPane.BOTTOM,false);
        //         contentPane.add(top, BorderLayout.BEFORE_FIRST_LINE);
        //         contentPane.add(bottom,BorderLayout.AFTER_LAST_LINE);
        //         if (Environment.isNewLaf())
        //            contentPane.setBackground(Color.WHITE);

        //         if (Environment.isMac()){
        //            //System.setProperty("apple.laf.useScreenMenuBar","true");
        //            //System.setProperty("com.apple.mrj.application.apple.menu.about.name", Messages.getMetaString("Text.ShortTitle"));
        //            JMenuBar menu = getMenuManager().getMenu(Environment.getStandAlone()?MenuManager.MAC_STANDARD_MENU:MenuManager.SERVER_STANDARD_MENU);
        //            //((JComponent)menu).setBorder(BorderFactory.createEmptyBorder());
        //
        //            ((JFrame)container).setJMenuBar(menu);
        //            projectListMenu = (JMenu) menu.getComponent(5);
        //         }

    } else if (Environment.isNewLook()) {
        if (Environment.isNeedToRestart()) {
            contentPane.add(new JLabel(Messages.getString("Error.restart")), BorderLayout.CENTER);
            return;
        }

        toolBar = getMenuManager().getToolBar(MenuManager.BIG_TOOL_BAR);
        if (!getLafManager().isToolbarOpaque())
            toolBar.setOpaque(false);
        if (!isApplet())
            getMenuManager().setActionVisible(ACTION_FULL_SCREEN, false);

        if (Environment.isExternal()) // external users only see project team
            getMenuManager().setActionVisible(ACTION_TEAM_FILTER, false);

        toolBar.addSeparator(new Dimension(20, 20));
        toolBar.add(new Box.Filler(new Dimension(0, 0), new Dimension(0, 0),
                new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE)));
        toolBar.add(((DefaultFrameManager) getFrameManager()).getProjectComboPanel());
        toolBar.add(Box.createRigidArea(new Dimension(20, 20)));
        if (Environment.isNewLaf())
            toolBar.setBackground(Color.WHITE);
        toolBar.setFloatable(false);
        toolBar.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        Box top;
        JComponent bottom;

        top = new Box(BoxLayout.Y_AXIS);
        toolBar.setAlignmentX(0.0f); // so it is left justified
        top.add(toolBar);

        JToolBar viewToolBar = getMenuManager().getToolBar(MenuManager.VIEW_TOOL_BAR_WITH_NO_SUB_VIEW_OPTION);
        topTabs = new TabbedNavigation();
        JComponent tabs = topTabs.createContentPanel(getMenuManager(), viewToolBar, 0, JTabbedPane.TOP, true);
        tabs.setAlignmentX(0.0f); // so it is left justified

        top.add(tabs);
        bottom = new TabbedNavigation().createContentPanel(getMenuManager(), viewToolBar, 1, JTabbedPane.BOTTOM,
                false);
        contentPane.add(top, BorderLayout.BEFORE_FIRST_LINE);
        contentPane.add(bottom, BorderLayout.AFTER_LAST_LINE);
        if (Environment.isNewLaf())
            contentPane.setBackground(Color.WHITE);

        if (Environment.isMac()) {
            //System.setProperty("apple.laf.useScreenMenuBar","true");
            //System.setProperty("com.apple.mrj.application.apple.menu.about.name", Messages.getMetaString("Text.ShortTitle"));
            JMenuBar menu = getMenuManager().getMenu(Environment.getStandAlone() ? MenuManager.MAC_STANDARD_MENU
                    : MenuManager.SERVER_STANDARD_MENU);
            //((JComponent)menu).setBorder(BorderFactory.createEmptyBorder());

            ((JFrame) container).setJMenuBar(menu);
            projectListMenu = (JMenu) menu.getComponent(5);
        }

    } else {

        toolBar = getMenuManager().getToolBar(
                Environment.isMac() ? MenuManager.MAC_STANDARD_TOOL_BAR : MenuManager.STANDARD_TOOL_BAR);
        filterToolBarManager = FilterToolBarManager.create(getMenuManager());
        filterToolBarManager.addButtons(toolBar);
        contentPane.add(toolBar, BorderLayout.BEFORE_FIRST_LINE);
        JToolBar viewToolBar = getMenuManager().getToolBar(MenuManager.VIEW_TOOL_BAR);
        viewToolBar.setOrientation(JToolBar.VERTICAL);
        viewToolBar.setRollover(true);
        contentPane.add(viewToolBar, BorderLayout.WEST);

        JMenuBar menu = getMenuManager().getMenu(Environment.getStandAlone()
                ? (Environment.isMac() ? MenuManager.MAC_STANDARD_MENU : MenuManager.STANDARD_MENU)
                : MenuManager.SERVER_STANDARD_MENU);

        if (!Environment.isMac()) {
            ((JComponent) menu).setBorder(BorderFactory.createEmptyBorder());
            JMenuItem logo = (JMenuItem) menu.getComponent(0);
            logo.setBorder(BorderFactory.createEmptyBorder());
            logo.setMaximumSize(new Dimension(124, 52));
            logo.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        }
        ((JFrame) container).setJMenuBar(menu);
        projectListMenu = (JMenu) menu.getComponent(Environment.isMac() ? 5 : 6);
    }

    //accelerators
    addCtrlAccel(KeyEvent.VK_G, ACTION_GOTO, null);
    addCtrlAccel(KeyEvent.VK_L, ACTION_GOTO, null);
    addCtrlAccel(KeyEvent.VK_F, ACTION_FIND, null);
    addCtrlAccel(KeyEvent.VK_Z, ACTION_UNDO, null); //- Sanhita
    addCtrlAccel(KeyEvent.VK_Y, ACTION_REDO, null);
    addCtrlAccel(KeyEvent.VK_N, ACTION_NEW_PROJECT, null);
    addCtrlAccel(KeyEvent.VK_O, ACTION_OPEN_PROJECT, null);
    addCtrlAccel(KeyEvent.VK_S, ACTION_SAVE_PROJECT, null);
    addCtrlAccel(KeyEvent.VK_P, ACTION_PRINT, null); //-Sanhita
    addCtrlAccel(KeyEvent.VK_I, ACTION_INSERT_TASK, null);
    addCtrlAccel(KeyEvent.VK_PERIOD, ACTION_INDENT, null);
    addCtrlAccel(KeyEvent.VK_COMMA, ACTION_OUTDENT, null);
    addCtrlAccel(KeyEvent.VK_PLUS, ACTION_EXPAND, new ExpandAction());
    addCtrlAccel(KeyEvent.VK_ADD, ACTION_EXPAND, new ExpandAction());
    addCtrlAccel(KeyEvent.VK_EQUALS, ACTION_EXPAND, new ExpandAction());
    addCtrlAccel(KeyEvent.VK_MINUS, ACTION_COLLAPSE, new CollapseAction());
    addCtrlAccel(KeyEvent.VK_SUBTRACT, ACTION_COLLAPSE, new CollapseAction());

    // To force a recalculation. This normally shouldn't be needed.
    addCtrlAccel(KeyEvent.VK_R, ACTION_RECALCULATE, new RecalculateAction());
}