Java Code Examples for java.awt.event.KeyEvent#VK_C

The following examples show how to use java.awt.event.KeyEvent#VK_C . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OpenTCSDrawingView.java    From openAGV with Apache License 2.0 6 votes vote down vote up
@Override
public void processKeyEvent(KeyEvent e) {
  if ((e.getModifiers() & KeyEvent.CTRL_MASK) != 0) {
    // Cut, copy, paste and duplicate
    if (e.getKeyCode() == KeyEvent.VK_X
        || e.getKeyCode() == KeyEvent.VK_C
        || e.getKeyCode() == KeyEvent.VK_V
        || e.getKeyCode() == KeyEvent.VK_D) {
      if (!appState.hasOperationMode(OperationMode.MODELLING)) {
        return;
      }
      processCutPasteKeyEvent();
    }
  }

  super.processKeyEvent(e);
}
 
Example 2
Source File: CopyAreaPerformance.java    From filthy-rich-clients with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Arrow keys scroll the view around. The 'c' key toggles clip area
 * optimization. The 'a' key toggles copyArea optimization.
 */
public void keyPressed(KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_RIGHT) {
        scroll(SCROLL_SIZE, 0);
    } else if (e.getKeyCode() == KeyEvent.VK_LEFT) {
        scroll(-SCROLL_SIZE, 0);
    } else if (e.getKeyCode() == KeyEvent.VK_UP) {
        scroll(0, -SCROLL_SIZE);
    } else if (e.getKeyCode() == KeyEvent.VK_DOWN) {
        scroll(0, SCROLL_SIZE);
    } else if (e.getKeyCode() == KeyEvent.VK_C) {
        useClip = !useClip;
        System.out.println("useClip = " + useClip);
    } else if (e.getKeyCode() == KeyEvent.VK_A) {
        useCopyArea = !useCopyArea;
        prevVX = -10000;
        System.out.println("useCopyArea = " + useCopyArea);
    }
}
 
Example 3
Source File: ClipboardKeyAdapter.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 6 votes vote down vote up
@Override
public void keyReleased(KeyEvent event) {
    if (event.isControlDown() || event.isMetaDown()) {
        switch (event.getKeyCode()) {
            case KeyEvent.VK_C:
                // Copy
                cancelEditing();
                XTableUtils.copyToClipboard(table, false);
                break;
            case KeyEvent.VK_X:
                // Cut
                cancelEditing();
                XTableUtils.copyToClipboard(table, true);
                break;
            case KeyEvent.VK_V:
                // Paste
                cancelEditing();
                XTableUtils.pasteFromClipboard(table);
                break;
            default:
                break;
        }
    }

}
 
Example 4
Source File: MTable.java    From javamelody with Apache License 2.0 5 votes vote down vote up
@Override
public void keyPressed(final KeyEvent event) {
	if (event.getSource() instanceof MTable) {
		final MTable<?> table = (MTable<?>) event.getSource();
		final int keyCode = event.getKeyCode();
		final int modifiers = event.getModifiers();
		if ((modifiers & java.awt.Event.CTRL_MASK) != 0 && keyCode == KeyEvent.VK_C) {
			event.consume();
			new MClipboardPrinter().print(table, null);
		}
	}
}
 
Example 5
Source File: ClipboardKeyAdapter.java    From gameserver with Apache License 2.0 5 votes vote down vote up
@Override
public void keyReleased(KeyEvent event) {
	if (event.isControlDown()) {
		if (event.getKeyCode() == KeyEvent.VK_C) { // Copy
			cancelEditing();
			copyToClipboard(false);
		} else if (event.getKeyCode() == KeyEvent.VK_X) { // Cut
			cancelEditing();
			copyToClipboard(true);
		} else if (event.getKeyCode() == KeyEvent.VK_V) { // Paste
			cancelEditing();
			pasteFromClipboard();
		}
	}
}
 
Example 6
Source File: SwingUtilities2.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if the given event is corrent gesture for
 * accessing clipboard
 *
 * @param ie InputEvent to check
 */
@SuppressWarnings("deprecation")
private static boolean isAccessClipboardGesture(InputEvent ie) {
    boolean allowedGesture = false;
    if (ie instanceof KeyEvent) { //we can validate only keyboard gestures
        KeyEvent ke = (KeyEvent)ie;
        int keyCode = ke.getKeyCode();
        int keyModifiers = ke.getModifiers();
        switch(keyCode) {
        case KeyEvent.VK_C:
        case KeyEvent.VK_V:
        case KeyEvent.VK_X:
            allowedGesture = (keyModifiers == InputEvent.CTRL_MASK);
            break;
        case KeyEvent.VK_INSERT:
            allowedGesture = (keyModifiers == InputEvent.CTRL_MASK ||
                              keyModifiers == InputEvent.SHIFT_MASK);
            break;
        case KeyEvent.VK_COPY:
        case KeyEvent.VK_PASTE:
        case KeyEvent.VK_CUT:
            allowedGesture = true;
            break;
        case KeyEvent.VK_DELETE:
            allowedGesture = ( keyModifiers == InputEvent.SHIFT_MASK);
            break;
        }
    }
    return allowedGesture;
}
 
Example 7
Source File: bug8020708.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
static void testInternalFrameMnemonic() throws Exception {
    Robot robot = new Robot();
    robot.setAutoDelay(50);

    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame = new JFrame("Test");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(300, 200);

            JDesktopPane desktop = new JDesktopPane();
            internalFrame = new JInternalFrame("Test");
            internalFrame.setSize(200, 100);
            internalFrame.setClosable(true);
            desktop.add(internalFrame);
            internalFrame.setVisible(true);
            internalFrame.setMaximizable(true);

            frame.getContentPane().add(desktop);
            frame.setVisible(true);
        }
    });

    robot.waitForIdle();

    Point clickPoint = Util.getCenterPoint(internalFrame);
    robot.mouseMove(clickPoint.x, clickPoint.y);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    robot.waitForIdle();

    Util.hitKeys(robot, KeyEvent.VK_CONTROL, KeyEvent.VK_SPACE);
    robot.waitForIdle();
    int keyCode = KeyEvent.VK_C;
    String mnemonic = UIManager
            .getString("InternalFrameTitlePane.closeButton.mnemonic");
    try {
        keyCode = Integer.parseInt(mnemonic);
    } catch (NumberFormatException e) {
    }
    Util.hitKeys(robot, keyCode);
    robot.waitForIdle();
    robot.delay(500);

    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            if (internalFrame.isVisible()) {
                throw new RuntimeException("Close mnemonic does not work in "+UIManager.getLookAndFeel());
            }
            frame.dispose();
        }
    });
}
 
Example 8
Source File: CopyCommand.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
private CopyCommand() {
    super(I18n.Text("Copy"), CMD_COPY, KeyEvent.VK_C);
}
 
Example 9
Source File: CopyToSheetCommand.java    From gcs with Mozilla Public License 2.0 4 votes vote down vote up
private CopyToSheetCommand() {
    super(I18n.Text("Copy to Character Sheet"), CMD_COPY_TO_SHEET, KeyEvent.VK_C, SHIFTED_COMMAND_MODIFIER);
}
 
Example 10
Source File: ConnectionTool.java    From workcraft with MIT License 4 votes vote down vote up
@Override
public int getHotKeyCode() {
    return KeyEvent.VK_C;
}
 
Example 11
Source File: Robot.java    From xnx3 with Apache License 2.0 4 votes vote down vote up
/**
 * 将字符型转换为按键码,可直接使用 {@link #press(int)}调用
 * @param key 字符型文字,包含 0~9 a~z .
 * @return 按键码
 */
public int StringToKey(String key){
	switch (key) {
	case "a":
		return KeyEvent.VK_A;
	case "b":
		return KeyEvent.VK_B;
	case "c":
		return KeyEvent.VK_C;
	case "d":
		return KeyEvent.VK_D;
	case "e":
		return KeyEvent.VK_E;
	case "f":
		return KeyEvent.VK_F;
	case "g":
		return KeyEvent.VK_G;
	case "h":
		return KeyEvent.VK_H;
	case "i":
		return KeyEvent.VK_I;
	case "j":
		return KeyEvent.VK_J;
	case "k":
		return KeyEvent.VK_K;
	case "l":
		return KeyEvent.VK_L;
	case "m":
		return KeyEvent.VK_M;
	case "n":
		return KeyEvent.VK_N;
	case "o":
		return KeyEvent.VK_O;
	case "p":
		return KeyEvent.VK_P;
	case "q":
		return KeyEvent.VK_Q;
	case "r":
		return KeyEvent.VK_R;
	case "s":
		return KeyEvent.VK_S;
	case "t":
		return KeyEvent.VK_T;
	case "u":
		return KeyEvent.VK_U;
	case "v":
		return KeyEvent.VK_V;
	case "w":
		return KeyEvent.VK_W;
	case "x":
		return KeyEvent.VK_X;
	case "y":
		return KeyEvent.VK_Y;
	case "z":
		return KeyEvent.VK_Z;
	case "0":
		return KeyEvent.VK_0;
	case "1":
		return KeyEvent.VK_1;
	case "2":
		return KeyEvent.VK_2;
	case "3":
		return KeyEvent.VK_3;
	case "4":
		return KeyEvent.VK_4;
	case "5":
		return KeyEvent.VK_5;
	case "6":
		return KeyEvent.VK_6;
	case "7":
		return KeyEvent.VK_7;
	case "8":
		return KeyEvent.VK_8;
	case "9":
		return KeyEvent.VK_9;
	case ".":
		return KeyEvent.VK_PERIOD;
	default:
		break;
	}
	
	return 0;
}
 
Example 12
Source File: KeyCodeToChar.java    From Repeat with Apache License 2.0 4 votes vote down vote up
private static String getUpperCaseAlphaChar(int code) {
	switch (code) {
	case KeyEvent.VK_Q:
		return "Q";
	case KeyEvent.VK_W:
		return "W";
	case KeyEvent.VK_E:
		return "E";
	case KeyEvent.VK_R:
		return "R";
	case KeyEvent.VK_T:
		return "T";
	case KeyEvent.VK_Y:
		return "Y";
	case KeyEvent.VK_U:
		return "U";
	case KeyEvent.VK_I:
		return "I";
	case KeyEvent.VK_O:
		return "O";
	case KeyEvent.VK_P:
		return "P";
	case KeyEvent.VK_A:
		return "A";
	case KeyEvent.VK_S:
		return "S";
	case KeyEvent.VK_D:
		return "D";
	case KeyEvent.VK_F:
		return "F";
	case KeyEvent.VK_G:
		return "G";
	case KeyEvent.VK_H:
		return "H";
	case KeyEvent.VK_J:
		return "J";
	case KeyEvent.VK_K:
		return "K";
	case KeyEvent.VK_L:
		return "L";
	case KeyEvent.VK_Z:
		return "Z";
	case KeyEvent.VK_X:
		return "X";
	case KeyEvent.VK_C:
		return "C";
	case KeyEvent.VK_V:
		return "V";
	case KeyEvent.VK_B:
		return "B";
	case KeyEvent.VK_N:
		return "N";
	case KeyEvent.VK_M:
		return "M";
	default:
		return "";
	}
}
 
Example 13
Source File: Patch.java    From TrakEM2 with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void keyPressed(final KeyEvent ke) {
	final Object source = ke.getSource();
	if (! (source instanceof DisplayCanvas)) return;
	final DisplayCanvas dc = (DisplayCanvas)source;
	final Roi roi = dc.getFakeImagePlus().getRoi();

	final int mod = ke.getModifiers();

	switch (ke.getKeyCode()) {
		case KeyEvent.VK_C:
			// copy into ImageJ clipboard
			// Ignoring masks: outside is already black, and ImageJ cannot handle alpha masks.
			if (0 == (mod ^ (Event.SHIFT_MASK | Event.ALT_MASK))) {
				// Place the source image, untransformed, into clipboard:
				final ImagePlus imp = getImagePlus();
				if (null != imp) imp.copy(false);
			} else if (0 == mod || (0 == (mod ^ Event.SHIFT_MASK))) {
				CoordinateTransformList<CoordinateTransform> list = null;
				if (hasCoordinateTransform()) {
					list = new CoordinateTransformList<CoordinateTransform>();
					list.add(getCoordinateTransform());
				}
				if (0 == mod) { //SHIFT is not down
					final AffineModel2D am = new AffineModel2D();
					am.set(this.at);
					if (null == list) list = new CoordinateTransformList<CoordinateTransform>();
					list.add(am);
				}
				ImageProcessor ip;
				if (null != list) {
					final TransformMesh mesh = new TransformMesh(list, meshResolution, o_width, o_height);
					final TransformMeshMapping mapping = new TransformMeshMapping(mesh);
					ip = mapping.createMappedImageInterpolated(getImageProcessor());
				} else {
					ip = getImageProcessor();
				}
				new ImagePlus(this.title, ip).copy(false);
			}
			ke.consume();
			break;
		case KeyEvent.VK_F:
			// fill mask with current ROI using
			if (null != roi && M.isAreaROI(roi)) {
				Bureaucrat.createAndStart(new Worker.Task("Filling image mask") {
					@Override
					public void exec() {
						getLayerSet().addDataEditStep(Patch.this);
						if (0 == mod) {
							addAlphaMask(roi, ProjectToolbar.getForegroundColorValue());
						} else if (0 == (mod ^ Event.SHIFT_MASK)) {
							// shift is down: fill outside
							try {
								final Area localRoi = M.areaInInts(M.getArea(roi)).createTransformedArea(at.createInverse());
								final Area invLocalRoi = new Area(new Rectangle(0, 0, getOWidth()	, getOHeight()));
								invLocalRoi.subtract(localRoi);
								addAlphaMaskLocal(invLocalRoi, ProjectToolbar.getForegroundColorValue());
							} catch (final NoninvertibleTransformException e) {
								IJError.print(e);
								return;
							}
						}
						getLayerSet().addDataEditStep(Patch.this);
						try { updateMipMaps().get(); } catch (final Throwable t) { IJError.print(t); } // wait
						Display.repaint();
					}
				}, project);
			}
			// capturing:
			ke.consume();
			break;
		default:
			super.keyPressed(ke);
			break;
	}
}
 
Example 14
Source File: Commander.java    From Scripts with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void keyPressed(final KeyEvent ke) {

	final int key = ke.getKeyCode();
	final Object source = ke.getSource();
	final boolean meta = (ke.getModifiers() & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) != 0;
	final boolean metaShift = meta && ke.isShiftDown();

	// Close if Esc, Ctrl+W or Cmd+W
	if (key == KeyEvent.VK_ESCAPE || (key == KeyEvent.VK_W && meta)) {
		quit();

		// Trigger Menu accelerators
	} else if (metaShift) {
		if (key == KeyEvent.VK_C) // Enter/Exit Console
			toggleConsoleMode();
		else if (key == KeyEvent.VK_G) // Go To...
			changeDirectory("");
		else if (!isConsoleMode() && key == KeyEvent.VK_R) // Reveal Path
			Utils.revealFile(path);

	} else if (meta) {

		if (key == KeyEvent.VK_L) {
			prompt.requestFocusInWindow();
			prompt.selectAll();
		} else if (key == KeyEvent.VK_B) {
			activateTable();
		} else if (key == KeyEvent.VK_COMMA) {
			showOptionsDialog();
		} else if (key == KeyEvent.VK_S) {
			saveQuery();
		} else if (!isConsoleMode() && key == KeyEvent.VK_D) {
			addBookmark();
		} else if (!isConsoleMode() && key == KeyEvent.VK_P) {
			printList();
		} else if (!isConsoleMode() && key == KeyEvent.VK_R) {
			resetFileList("Contents reloaded...");
		}

	} else if (source == prompt) {

		// Up or down arrows pressed in prompt: Move the focus to list
		if (key == KeyEvent.VK_UP || key == KeyEvent.VK_DOWN) {
			activateTable();
		}

	} else if (source == table) {

		// Focus in list and left arrow key: move up in directory hierarchy
		if (key == KeyEvent.VK_LEFT) {
			selectParentDirectory(path);
			setSelectedItem(table.getSelectedRow());

			// Focus in list and right arrow key: List sub-directory
		} else if (key == KeyEvent.VK_RIGHT) {
			setSelectedItem(table.getSelectedRow());
			if (isFolder(selectedItem))
				selectSubDirectory(selectedItem);

			// Focus in list and enter: Open selected item
		} else if (key == KeyEvent.VK_ENTER) {
			ke.consume();
			setSelectedItem(table.getSelectedRow());
			openItem(selectedItem);

			// Focus in list and backspace: Switch focus back to prompt
		} else if (key == KeyEvent.VK_BACK_SPACE) {
			prompt.requestFocusInWindow();
			prompt.selectAll();

			// Focus in list and up/down arrow key: Loop through list
		} else if (key == KeyEvent.VK_UP) {
			if (table.getSelectedRow() == 0)
				table.setRowSelectionInterval(tableModel.getRowCount() - 1, tableModel.getRowCount() - 1);
		} else if (key == KeyEvent.VK_DOWN) {
			if (table.getSelectedRow() == tableModel.getRowCount() - 1)
				table.setRowSelectionInterval(0, 0);
		}

	}

}
 
Example 15
Source File: MainFrame.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/**
 * Creates the file menu.
 */
private void createFileMenu() {
  this.fileMenu = new JMenu("File");

  // Standard text file menu items.
  JMenuItem newTextItem = new JMenuItem("New Text...", KeyEvent.VK_N);
  newTextItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK));
  newTextItem.addActionListener(new NewTextEventHandler(this));
  this.fileMenu.add(newTextItem);
  this.fileMenu.setMnemonic(KeyEvent.VK_F);
  JMenuItem fileOpen = new JMenuItem("Open Text File", KeyEvent.VK_O);
  fileOpen.addActionListener(new FileOpenEventHandler(this));
  fileOpen.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));
  this.fileMenu.add(fileOpen);
  this.fileSaveItem = new JMenuItem("Save Text File", KeyEvent.VK_S);
  this.fileSaveItem.setEnabled(false);
  this.fileSaveItem.addActionListener(new FileSaveEventHandler(this));
  this.fileSaveItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
  this.fileMenu.add(this.fileSaveItem);
  JMenuItem fileSaveAsItem = new JMenuItem("Save Text As...", KeyEvent.VK_A);
  fileSaveAsItem.addActionListener(new FileSaveAsEventHandler(this));
  this.fileMenu.add(fileSaveAsItem);
  createCPMenu();
  this.cpMenu.setMnemonic(KeyEvent.VK_P);
  this.fileMenu.add(this.cpMenu);
  this.fileMenu.addSeparator();
  this.recentTextFileMenu = new JMenu("Recently used ...");
  this.recentTextFileMenu.setMnemonic(KeyEvent.VK_U);
  this.fileMenu.add(this.recentTextFileMenu);
  this.fileMenu.addSeparator();

  // Color preferences
  JMenuItem colorPrefsOpenItem = new JMenuItem("Load Color Settings", KeyEvent.VK_L);
  colorPrefsOpenItem.addActionListener(new ColorPrefsOpenHandler(this));
  this.fileMenu.add(colorPrefsOpenItem);
  JMenuItem colorPrefsSaveItem = new JMenuItem("Save Color Settings", KeyEvent.VK_C);
  colorPrefsSaveItem.addActionListener(new ColorPrefsSaveHandler(this));
  this.fileMenu.add(colorPrefsSaveItem);
  this.fileMenu.addSeparator();

  // Reading and writing type system files.
  this.typeSystemReadItem = new JMenuItem("Read Type System File");
  this.typeSystemReadItem.setEnabled(true);
  this.typeSystemReadItem.addActionListener(new TypeSystemFileOpenEventHandler(this));
  this.fileMenu.add(this.typeSystemReadItem);
  this.typeSystemWriteItem = new JMenuItem("Write Type System File");
  this.typeSystemWriteItem.addActionListener(new XCASSaveTSHandler(this));
  this.fileMenu.add(this.typeSystemWriteItem);
  this.fileMenu.addSeparator();

  // Reading and writing XMI CAS files.
  this.xmiCasReadItem = new JMenuItem("Read XMI CAS File");
  this.xmiCasReadItem.addActionListener(new XmiCasFileOpenHandler(this));
  this.fileMenu.add(this.xmiCasReadItem);
  this.xmiCasWriteItem = new JMenuItem("Write XMI CAS File");
  this.xmiCasWriteItem.addActionListener(new XmiCasSaveHandler(this));
  this.fileMenu.add(this.xmiCasWriteItem);
  this.fileMenu.addSeparator();

  // Reading and writing old-style XCAS files.
  this.xcasReadItem = new JMenuItem("Read XCAS File", KeyEvent.VK_R);
  this.xcasReadItem.addActionListener(new XCASFileOpenEventHandler(this));
  this.fileMenu.add(this.xcasReadItem);
  this.xcasWriteItem = new JMenuItem("Write XCAS File", KeyEvent.VK_W);
  this.xcasWriteItem.addActionListener(new XCASSaveHandler(this));
  this.fileMenu.add(this.xcasWriteItem);
  this.fileMenu.addSeparator();
  JMenuItem exit = new JMenuItem("Exit", KeyEvent.VK_X);
  exit.addActionListener(new SystemExitHandler(this));
  this.fileMenu.add(exit);

  // Disable menu items that can't be executed yet.
  this.typeSystemWriteItem.setEnabled(false);
  setEnableCasFileReadingAndWriting();
}
 
Example 16
Source File: AWTConsole.java    From beanshell with Apache License 2.0 4 votes vote down vote up
public void type(int code, char ch, int modifiers ) {
        switch ( code ) {
            case KeyEvent.VK_BACK_SPACE:
                if (line.length() > 0) {
                    line.setLength( line.length() - 1 );
                    replaceRange( "", textLength-1, textLength );
                    textLength--;
                }
                break;
            case KeyEvent.VK_ENTER:
                enter();
                break;
            case KeyEvent.VK_U:
                if ( (modifiers & InputEvent.CTRL_DOWN_MASK) > 0 ) {
                    int len = line.length();
                    replaceRange( "", textLength-len, textLength );
                    line.setLength( 0 );
                    histLine = 0;
                    textLength = getText().length();
                } else
                    doChar( ch );
                break;
            case KeyEvent.VK_UP:
                historyUp();
                break;
            case KeyEvent.VK_DOWN:
                historyDown();
                break;
            case KeyEvent.VK_TAB:
                line.append("    ");
                append("    ");
                textLength +=4;
                break;
/*
            case KeyEvent.VK_LEFT:
                if (line.length() > 0) {
                break;
*/
            // Control-C
            case KeyEvent.VK_C:
                if ( (modifiers & InputEvent.CTRL_DOWN_MASK) > 0 ) {
                    line.append("^C");
                    append("^C");
                    textLength += 2;
                } else
                    doChar( ch );
                break;
            default:
                doChar( ch );
        }
    }
 
Example 17
Source File: MainFrameKeyListener.java    From tankbattle with MIT License 4 votes vote down vote up
@Override
public void keyPressed(KeyEvent e) {
    RealTimeGameData data = gameContext.getRealTimeGameData();



    if (Boolean.TRUE.equals(data.getMapMakingFlag()) && e.getKeyCode() == KeyEvent.VK_C) {
        if (data.getCurrentStuff() == StuffTypeEnum.BRICK) {
            data.setCurrentStuff(StuffTypeEnum.IRON);
        } else if (data.getCurrentStuff() == StuffTypeEnum.IRON) {
            data.setCurrentStuff(StuffTypeEnum.WATER);
        } else if (data.getCurrentStuff() == StuffTypeEnum.WATER) {
            data.setCurrentStuff(StuffTypeEnum.INVALID);
        } else {
            data.setCurrentStuff(StuffTypeEnum.BRICK);
        }

    }


    if (e.getKeyCode() == KeyEvent.VK_P) { // 暂停
        gameEventService.gameEventStop(data);
    }

    data.getMyTanks().forEach(myTank -> {
        if (!myTank.getLive()) {
            data.keyPressedDirect(false, false, false, false);
        } else {
            if ((e.getKeyCode() == KeyEvent.VK_UP)) {
                myTank.setDirect(DirectionEnum.NORTH);
                data.keyPressedDirect(true, false, false, false);

            } else if ((e.getKeyCode() == KeyEvent.VK_DOWN) && myTank.getY() <= 580) {
                myTank.setDirect(DirectionEnum.SOUTH);
                data.keyPressedDirect(false, true, false, false);

            } else if ((e.getKeyCode() == KeyEvent.VK_LEFT) && myTank.getY() <= 580) {
                myTank.setDirect(DirectionEnum.WEST);
                data.keyPressedDirect(false, false, true, false);

            } else if ((e.getKeyCode() == KeyEvent.VK_RIGHT) && myTank.getY() <= 580) {
                myTank.setDirect(DirectionEnum.EAST);
                data.keyPressedDirect(false, false, false, true);

            }
            if (e.getKeyCode() == KeyEvent.VK_X && myTank.getY() <= 580) {
                if (myTank.getBullets().size() <= 1 && data.getMyBulletNum() > 0) {
                    data.setMyBulletNum(data.getMyBulletNum() - 1);
                    gameEventService.shot(myTank);
                }
            }
        }
    });

}
 
Example 18
Source File: MainFrame.java    From uima-uimaj with Apache License 2.0 4 votes vote down vote up
/**
 * Creates the tools menu.
 *
 * @return the j menu
 */
private JMenu createToolsMenu() {
  JMenu toolsMenu = new JMenu("Tools");
  toolsMenu.setMnemonic(KeyEvent.VK_T);
  this.tsViewerItem = new JMenuItem("View Typesystem", KeyEvent.VK_T);
  this.tsViewerItem.addActionListener(new ShowTypesystemHandler(this));
  this.tsViewerItem.setEnabled(false);
  toolsMenu.add(this.tsViewerItem);
  this.allAnnotationViewerItem = new JMenuItem("Show Selected Annotations", KeyEvent.VK_A);
  this.allAnnotationViewerItem.addActionListener(new ShowAnnotatedTextHandler(this));
  toolsMenu.add(this.allAnnotationViewerItem);
  this.allAnnotationViewerItem.setEnabled(false);
  this.acdItem = new JMenuItem("Customize Annotation Display", KeyEvent.VK_C);
  toolsMenu.add(this.acdItem);
  this.acdItem.setEnabled(false);
  this.acdItem.addActionListener(new ShowAnnotationCustomizerHandler(this));

  JMenu logConfig = new JMenu("Set Log Level");
  ButtonGroup levelGroup = new ButtonGroup();

  // get current log level setting
  String curLogLevel = LogManager.getLogManager().getProperty(".level");

  // create log config menu with available log levels
  Iterator<Level> levelIt = MainFrame.logLevels.iterator();
  while (levelIt.hasNext()) {
    Level level = levelIt.next();
    JRadioButtonMenuItem item = new JRadioButtonMenuItem(level.toString());
    // select current log level
    if (level.toString().equals(curLogLevel)) {
      item.setSelected(true);
    }
    item.addActionListener(new SetLogConfigHandler());
    levelGroup.add(item);
    logConfig.add(item);
  }
  toolsMenu.add(logConfig);

  JMenuItem logViewer = new JMenuItem("View Log File", KeyEvent.VK_L);
  logViewer.addActionListener(new ActionListener() {

    @Override
    public void actionPerformed(ActionEvent event) {
      LogFileViewer viewer = new LogFileViewer("Log file: "
          + MainFrame.this.logFile.getAbsolutePath());
      viewer.addWindowListener(new CloseLogViewHandler(MainFrame.this));
      Dimension dim = getDimension(logViewSizePref);
      if (dim == null) {
        dim = logFileDimensionDefault;
      }
      viewer.init(MainFrame.this.logFile, dim);
    }
  });
  toolsMenu.add(logViewer);

  return toolsMenu;
}
 
Example 19
Source File: PlotFrame.java    From opt4j with MIT License 4 votes vote down vote up
/**
 * Construct a plot frame with the specified title and the specified
 * instance of PlotBox. After constructing this, it is necessary to call
 * setVisible(true) to make the plot appear.
 * 
 * @param title
 *            The title to put on the window.
 * @param plotArg
 *            the plot object to put in the frame, or null to create an
 *            instance of Plot.
 */
public PlotFrame(String title, PlotBox plotArg) {
	super(title);

	// The Java look & feel is pretty lame, so we use the native
	// look and feel of the platform we are running on.
	try {
		UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
	} catch (Exception e) {
		// Ignore exceptions, which only result in the wrong look and feel.
	}

	if (plotArg == null) {
		plot = new Plot();
	} else {
		plot = plotArg;
	}

	// Background color is a light grey.
	plot.setBackground(new Color(0xe5e5e5));

	_fileMenu.setMnemonic(KeyEvent.VK_F);
	_editMenu.setMnemonic(KeyEvent.VK_E);
	_specialMenu.setMnemonic(KeyEvent.VK_S);

	// File menu
	JMenuItem[] fileMenuItems = { new JMenuItem("Open", KeyEvent.VK_O), new JMenuItem("Save", KeyEvent.VK_S),
			new JMenuItem("SaveAs", KeyEvent.VK_A), new JMenuItem("Export", KeyEvent.VK_E),
			new JMenuItem("Print", KeyEvent.VK_P), new JMenuItem("Close", KeyEvent.VK_C), };

	// Open button = ctrl-o.
	fileMenuItems[0].setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, Event.CTRL_MASK));

	// Save button = ctrl-s.
	fileMenuItems[1].setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, Event.CTRL_MASK));

	// Print button = ctrl-p.
	fileMenuItems[4].setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, Event.CTRL_MASK));

	// Close button = ctrl-w.
	fileMenuItems[5].setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, Event.CTRL_MASK));

	FileMenuListener fml = new FileMenuListener();

	// Set the action command and listener for each menu item.
	for (int i = 0; i < fileMenuItems.length; i++) {
		fileMenuItems[i].setActionCommand(fileMenuItems[i].getText());
		fileMenuItems[i].addActionListener(fml);
		_fileMenu.add(fileMenuItems[i]);
	}

	_menubar.add(_fileMenu);

	// Edit menu
	JMenuItem format = new JMenuItem("Format", KeyEvent.VK_F);
	FormatListener formatListener = new FormatListener();
	format.addActionListener(formatListener);
	_editMenu.add(format);
	_menubar.add(_editMenu);

	// Special menu
	JMenuItem[] specialMenuItems = { new JMenuItem("About", KeyEvent.VK_A), new JMenuItem("Help", KeyEvent.VK_H),
			new JMenuItem("Clear", KeyEvent.VK_C), new JMenuItem("Fill", KeyEvent.VK_F),
			new JMenuItem("Reset axes", KeyEvent.VK_R), new JMenuItem("Sample plot", KeyEvent.VK_S), };
	SpecialMenuListener sml = new SpecialMenuListener();

	// Set the action command and listener for each menu item.
	for (int i = 0; i < specialMenuItems.length; i++) {
		specialMenuItems[i].setActionCommand(specialMenuItems[i].getText());
		specialMenuItems[i].addActionListener(sml);
		_specialMenu.add(specialMenuItems[i]);
	}

	_menubar.add(_specialMenu);

	setJMenuBar(_menubar);

	getContentPane().add(plot, BorderLayout.CENTER);

	// FIXME: This should not be hardwired in here.
	setSize(500, 300);

	// Center.
	Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
	Dimension frameSize = getSize();
	int x = (screenSize.width - frameSize.width) / 2;
	int y = (screenSize.height - frameSize.height) / 2;
	setLocation(x, y);
}
 
Example 20
Source File: DQ.java    From javagame with MIT License 4 votes vote down vote up
/**
 * �L�[�������ꂽ��L�[�̏�Ԃ��u�����ꂽ�v�ɕς���
 * 
 * @param e �L�[�C�x���g
 */
public void keyPressed(KeyEvent e) {
    int keyCode = e.getKeyCode();

    // �I������
    if (keyCode == KeyEvent.VK_ESCAPE || keyCode == KeyEvent.VK_Q ||
            keyCode == KeyEvent.VK_END ||
            (keyCode == KeyEvent.VK_C && e.isControlDown())) {
        running = false;
    }

    if (keyCode == KeyEvent.VK_LEFT) {
        if (commandWindow.isVisible()) {
            cmdLeftKey.press();
        } else {
            leftKey.press();
        }
    }
    if (keyCode == KeyEvent.VK_RIGHT) {
        if (commandWindow.isVisible()) {
            cmdRightKey.press();
        } else {
            rightKey.press();
        }
    }
    if (keyCode == KeyEvent.VK_UP) {
        if (commandWindow.isVisible()) {
            cmdUpKey.press();
        } else {
            upKey.press();
        }
    }
    if (keyCode == KeyEvent.VK_DOWN) {
        if (commandWindow.isVisible()) {
            cmdDownKey.press();
        } else {
            downKey.press();
        }
    }
    if (keyCode == KeyEvent.VK_SPACE) {
        spaceKey.press();
    }
}