Java Code Examples for java.awt.event.KeyEvent

The following are top voted examples for showing how to use java.awt.event.KeyEvent. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: sumo   File: GeometricInteractiveVDSLayerPanel.java   View source code 6 votes vote down vote up
public void keyReleased(KeyEvent e) {
	FlagTable t=(FlagTable)e.getSource();
    int id = e.getID();
    if(id == e.KEY_RELEASED && e.getKeyChar() == e.VK_BACK_SPACE)
    {
        if(t.getSelectedRow() != -1)
            for(int i:t.getSelectedRows()){
            	GeometryImage gl=((ComplexEditVDSVectorLayer)layer).getGeometriclayer();
            	Geometry geom=gl.getGeometries().get(i);
            	deleted.add(0,geom);
                attrDeleted.add(0,(gl).getAttributes(geom));
            	((GeometricInteractiveVDSLayerModel)t.getModel()).removeSelection(i);
            	glm.fireTableDataChanged();
            	if(gl.getGeometries().size()>0){
            		int sel=0;
            		if(i>0&&i<(gl.getGeometries().size()-1))
            			sel=i;
            		((GeometricInteractiveVDSLayerModel)t.getModel()).changeSelection(sel, display);
            		glm.changeSelection(sel, true);
            		((JTable)e.getSource()).setRowSelectionInterval(sel,sel);
            	}
            }
        this.repaint();
        ((GeometricInteractiveVDSLayerModel)t.getModel()).changeSelection(t.getSelectedRow(), display);
    }
}
 
Example 2
Project: PassBox   File: Login_Page.java   View source code 6 votes vote down vote up
public void keyPressed(KeyEvent e) {
    if (e.getKeyCode()==KeyEvent.VK_ENTER){
        String sorgu = "SELECT * FROM passbox_db.users_tb where username=? and password=?;";
    try {
        pst=baglanti.prepareStatement(sorgu);
        pst.setString(1, username_txt.getText());
        pst.setString(2, password_txt.getText());
        gelenveri=pst.executeQuery();
        if(gelenveri.next()){
            JOptionPane.showMessageDialog(null,"Başarılı giriş!");
            this.setVisible(false);
            User_Control_Panel_Page frame = new User_Control_Panel_Page();
            frame.setVisible(true);
        }
        else{
        JOptionPane.showMessageDialog(null,"Başarısız giriş!");
        }
    } catch (SQLException ex) {
        JOptionPane.showConfirmDialog(null, "Sorgu da hata var!");
    }
    }
}
 
Example 3
Project: vexillo   File: CopySVGMenuItem.java   View source code 6 votes vote down vote up
public CopySVGMenuItem(final FlagFrame frame) {
	setText("Copy SVG");
	if (!OSUtils.isMacOS()) setMnemonic(KeyEvent.VK_S);
	setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputUtils.META_SHIFT_MASK));
	if (frame == null) {
		setEnabled(false);
	} else {
		addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				SVGExporter s = new SVGExporter(frame.getFlagFile(), frame.getFlag());
				String svg = s.exportToString(frame.getViewerWidth(), frame.getViewerHeight(), frame.getGlaze());
				StringSelection ss = new StringSelection(svg);
				Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
				cb.setContents(ss, ss);
			}
		});
	}
}
 
Example 4
Project: jaer   File: IPotSliderTextControl.java   View source code 6 votes vote down vote up
private void valueTextFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_valueTextFieldKeyPressed
        // key pressed in text field
        //        System.out.println("keyPressed evt "+evt);
//        System.out.println("value field key pressed");
        endEdit();
//        String s = evt.getKeyText(evt.getKeyCode());
        int code = evt.getKeyCode();
        boolean shift = evt.isShiftDown();
        float byRatio = 1.1f;
        if (shift) {
            byRatio = 10f;
        }
        if (code == KeyEvent.VK_UP) {
            startEdit();
            pot.changeByRatio(byRatio);
            endEdit();
        } else if (code == KeyEvent.VK_DOWN) {
            startEdit();
            pot.changeByRatio(1f / byRatio);
            endEdit();
        }
    }
 
Example 5
Project: incubator-netbeans   File: CheckListener.java   View source code 6 votes vote down vote up
public void keyPressed(KeyEvent e) {
    if (e.getKeyChar() == ' ') {
        JTree tree = (JTree) e.getSource();
        TreePath path = tree.getSelectionPath();
        if( null == path )
            return;

        Node node = Visualizer.findNode( path.getLastPathComponent() );
        if( null == node )
            return;
        
        boolean isSelected = settings.isNodeVisible( node );
        settings.setNodeVisible( node, !isSelected );
        tree.repaint();
        
        e.consume();
    }
}
 
Example 6
Project: incubator-netbeans   File: FixImportsTest.java   View source code 6 votes vote down vote up
public void testCancel() {
    Node pn = new ProjectsTabOperator().getProjectRootNode(TEST_PROJECT_NAME);
    pn.select();
    
    Node n = new Node(pn, org.netbeans.jellytools.Bundle.getString(
            "org.netbeans.modules.java.j2seproject.Bundle",
            "NAME_src.dir")+"|"+TEST_PACKAGE_NAME+"|"
            +TEST_CLASS_NAME);
    n.select();
    new OpenAction().perform();
    EditorOperator editor = new EditorOperator(TEST_CLASS_NAME);
    try {
        editor.insert("List m;\n", 46, 1);
        Utilities.takeANap(100);
        MainWindowOperator.getDefault().pushKey(KeyEvent.VK_I,
                KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK);            
        FixAllImports fio = new FixAllImports();
        fio.cancel();
        assertFalse("Import is added",editor.getText().contains("import java.util.List;"));
    } finally {
        editor.close(false);
    }
}
 
Example 7
Project: smile_1.5.0_java7   File: FontChooser.java   View source code 6 votes vote down vote up
@Override
public void keyPressed(KeyEvent e) {
    switch (e.getKeyCode()) {
        case KeyEvent.VK_UP:
            int up = targetList.getSelectedIndex() - 1;
            if (up < 0) {
                up = 0;
            }
            targetList.setSelectedIndex(up);
            break;
        case KeyEvent.VK_DOWN:
            int listSize = targetList.getModel().getSize();
            int down = targetList.getSelectedIndex() + 1;
            if (down >= listSize) {
                down = listSize - 1;
            }
            targetList.setSelectedIndex(down);
            break;
        default:
            break;
    }
}
 
Example 8
Project: AgentWorkbench   File: TableCellSpinnerEditor4FloatObject.java   View source code 6 votes vote down vote up
@Override
public void keyPressed(KeyEvent e) {
	if(e.getKeyCode() == KeyEvent.VK_ENTER || e.getKeyCode() == KeyEvent.VK_TAB){
		try {
			((JSpinner)editorComponent).commitEdit();
			
		} catch (ParseException e1) {
			DefaultEditor de = (DefaultEditor) ((JSpinner)editorComponent).getEditor();
			String text = de.getTextField().getText();
			if(text.matches("^\\d+(\\.\\d*)?")){
				((JSpinner)editorComponent).setValue(Float.parseFloat(text));
			}else{
				System.err.println("Invalid input - ignoring");
			}
		}
	}
	super.keyPressed(e);
}
 
Example 9
Project: Logisim   File: MemPoker.java   View source code 6 votes vote down vote up
@Override
public void keyTyped(InstanceState state, KeyEvent e) {
	char c = e.getKeyChar();
	int val = Character.digit(e.getKeyChar(), 16);
	MemState data = (MemState) state.getData();
	if (val >= 0) {
		curValue = curValue * 16 + val;
		data.getContents().set(data.getCursor(), curValue);
		state.fireInvalidated();
	} else if (c == ' ' || c == '\t') {
		moveTo(data, data.getCursor() + 1);
	} else if (c == '\r' || c == '\n') {
		moveTo(data, data.getCursor() + data.getColumns());
	} else if (c == '\u0008' || c == '\u007f') {
		moveTo(data, data.getCursor() - 1);
	}
}
 
Example 10
Project: openjdk-jdk10   File: bug4524490.java   View source code 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    Robot robot = new Robot();
    robot.setAutoDelay(50);

    UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");

    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            fileChooser = new JFileChooser();
            fileChooser.showOpenDialog(null);
        }
    });

    robot.waitForIdle();

    if (OSInfo.OSType.MACOSX.equals(OSInfo.getOSType())) {
        Util.hitKeys(robot, KeyEvent.VK_CONTROL, KeyEvent.VK_ALT, KeyEvent.VK_L);
    } else {
        Util.hitKeys(robot, KeyEvent.VK_ALT, KeyEvent.VK_L);
    }
    checkFocus();
}
 
Example 11
Project: scorekeeperfrontend   File: RunsTable.java   View source code 6 votes vote down vote up
public RunsTable(EntryModel m)
{
	super(m, new TimeRenderer(), new RunsTransferHandler(), 2, Integer.MAX_VALUE);
	
	InputMap im = getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
	im.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "cut"); // delete is same as Ctl+X
	im.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "Enter Time");
	
	registerKeyboardAction(
		this,
		"Enter Time",
		KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),
		JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
	);
	
	Messenger.register(MT.TIME_ENTERED, this);
}
 
Example 12
Project: jaer   File: ConfigurableIPotGUIControl.java   View source code 6 votes vote down vote up
private void biasTextFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_biasTextFieldKeyPressed
        int code = evt.getKeyCode();
        boolean shifted = evt.isShiftDown();
        final float byRatio = 1.02f;
        if (code == KeyEvent.VK_UP) {
            startEdit();
            if (shifted) {
                pot.setBitValue(pot.getBitValue() + 1);
            } else {
                pot.changeByRatio(byRatio);
            }
            endEdit();
        } else if (code == KeyEvent.VK_DOWN) {
            startEdit();
            if (shifted) {
                pot.setBitValue(pot.getBitValue() - 1);
            } else {
                pot.changeByRatio(1f / byRatio);
            }
            endEdit();
        }
}
 
Example 13
Project: incubator-netbeans   File: Utilities.java   View source code 6 votes vote down vote up
/**
 * Creates nice textual representation of KeyStroke.
 * Modifiers and an actual key label are concated by plus signs
 * @param the KeyStroke to get description of
 * @return String describing the KeyStroke
 */
public static String keyStrokeToString( KeyStroke stroke ) {
    String modifText = KeyEvent.getKeyModifiersText( stroke.getModifiers() );
    String keyText = (stroke.getKeyCode() == KeyEvent.VK_UNDEFINED) ? 
        String.valueOf(stroke.getKeyChar()) : getKeyText(stroke.getKeyCode());
    if( modifText.length() > 0 ) return modifText + '+' + keyText;
    else return keyText;
}
 
Example 14
Project: openjdk-jdk10   File: AWTTextKeyboardDriver.java   View source code 6 votes vote down vote up
@Override
public NavigationKey[] getKeys(ComponentOperator oper) {
    boolean multiString = oper instanceof TextAreaOperator;
    NavigationKey[] result = new NavigationKey[multiString ? 4 : 2];
    result[0] = new UpKey(KeyEvent.VK_LEFT, 0);
    result[1] = new DownKey(KeyEvent.VK_RIGHT, 0);
    ((UpKey) result[0]).setDownKey((DownKey) result[1]);
    ((DownKey) result[1]).setUpKey((UpKey) result[0]);
    if (multiString) {
        result[2] = new UpKey(KeyEvent.VK_UP, 0);
        result[3] = new DownKey(KeyEvent.VK_DOWN, 0);
        ((UpKey) result[2]).setDownKey((DownKey) result[3]);
        ((DownKey) result[3]).setUpKey((UpKey) result[2]);
    }
    return result;
}
 
Example 15
Project: incubator-netbeans   File: IncrementalSearchTest.java   View source code 6 votes vote down vote up
public void testNotFound() {
    openDefaultProject();
    openFile("Source Packages|org.netbeans.test.editor.search.IncrementalSearchTest", "match.txt");
    EditorOperator editor = new EditorOperator("match.txt");
    editor.setCaretPosition(3, 1);
    SearchBarOperator barOperator = SearchBarOperator.invoke(editor);
    JTextComponentOperator t = barOperator.findCombo();
    try {            
        t.clearText();
        new EventTool().waitNoEvent(100);
        t.requestFocus();
        t.typeText("XYZ");        
        t.pushKey(KeyEvent.VK_ENTER);                        
        new EventTool().waitNoEvent(100);            
        MainWindowOperator mwo =  MainWindowOperator.getDefault();
        assertEquals("'XYZ' not found",mwo.getStatusText());                        
        JTextComponentOperator filed = barOperator.findCombo();
        assertEquals(new Color(178, 0, 0), filed.getForeground());                
    } finally {
        barOperator.closeButton().doClick();                              
    }
    new EventTool().waitNoEvent(200);
    assertFalse("ToolBar not closed",barOperator.isVisible());
    editor.closeDiscard();
}
 
Example 16
Project: openjdk-jdk10   File: TextKeyboardDriver.java   View source code 6 votes vote down vote up
@Override
public void clearText(ComponentOperator oper) {
    DriverManager.getFocusDriver(oper).giveFocus(oper);
    checkSupported(oper);
    KeyDriver kdriver = DriverManager.getKeyDriver(oper);
    Timeout pushTime = oper.getTimeouts().create("ComponentOperator.PushKeyTimeout");
    Timeout betweenTime = getBetweenTimeout(oper);
    while (getCaretPosition(oper) > 0) {
        kdriver.typeKey(oper, KeyEvent.VK_BACK_SPACE, (char) KeyEvent.VK_BACK_SPACE, 0, pushTime);
        betweenTime.sleep();
    }
    while (getText(oper).length() > 0) {
        kdriver.pushKey(oper, KeyEvent.VK_DELETE, 0, pushTime);
        betweenTime.sleep();
    }
}
 
Example 17
Project: AI-RRT-Motion-Planning   File: Visualiser.java   View source code 6 votes vote down vote up
private void createFileMenu() {
	fileMenu = new JMenu("File");
	fileMenu.setMnemonic(KeyEvent.VK_F);
	fileMenu.getAccessibleContext().setAccessibleDescription(
			"Load configs or close the app.");
	menuBar.add(fileMenu);

	loadProblemItem = new JMenuItem("Load problem");
	loadProblemItem.setMnemonic(KeyEvent.VK_P);
	loadProblemItem.addActionListener(menuListener);
	fileMenu.add(loadProblemItem);

	loadSolutionItem = new JMenuItem("Load solution");
	loadSolutionItem.setMnemonic(KeyEvent.VK_S);
	loadSolutionItem.addActionListener(menuListener);
	loadSolutionItem.setEnabled(false);
	fileMenu.add(loadSolutionItem);

	fileMenu.addSeparator();
	exitItem = new JMenuItem("Exit");
	exitItem.setMnemonic(KeyEvent.VK_X);
	exitItem.addActionListener(menuListener);
	fileMenu.add(exitItem);
}
 
Example 18
Project: incubator-netbeans   File: RemoveSurroundingTest.java   View source code 5 votes vote down vote up
private void dumpAndSelect(int row, int col, int select) {
    oper.setCaretPosition(row, col);
    oper.pressKey(KeyEvent.VK_BACK_SPACE, KeyEvent.ALT_DOWN_MASK);
    JDialogOperator jdo = new JDialogOperator(MainWindowOperator.getDefault());
    JListOperator jlo = new JListOperator(jdo);
    ListModel model = jlo.getModel();
    int i;
    for (i = 0; i < model.getSize(); i++) {
        Object item = model.getElementAt(i);
        if(item instanceof CodeDeleter) {
            CodeDeleter codeDeleter = (CodeDeleter) item;
            ref(codeDeleter.getDisplayName());                
            HighlightsSequence highlights = codeDeleter.getHighlight().getHighlights(0, oper.getText().length());
            while(highlights.moveNext()) {
                ref(highlights.getStartOffset()+" "+highlights.getEndOffset());
                AttributeSet attributes = highlights.getAttributes();
                Enumeration<?> attributeNames = attributes.getAttributeNames();
                while(attributeNames.hasMoreElements()) {
                    Object nextElement = attributeNames.nextElement();
                    ref(nextElement+" "+attributes.getAttribute(nextElement));
                }
            }
        }            
    }
    if(select>-1) {
        jlo.selectItem(select);
        ref(oper.getText());
    }        
}
 
Example 19
Project: openjdk-jdk10   File: TestPopupMenu.java   View source code 5 votes vote down vote up
public TestPopupMenu() throws Exception {
    Robot robot = new Robot();
    robot.setAutoDelay(200);
    try {
        SwingUtilities.invokeAndWait(() -> {
            try {
                createAndShowUI();
            } catch (Exception ex) {
                throw new RuntimeException(ex);
            }
        });
        blockTillDisplayed(label);
        robot.waitForIdle();
        robot.mouseMove(p.x + d.width/2, p.y + d.height/2);
        robot.mousePress(InputEvent.BUTTON3_DOWN_MASK);
        robot.mouseRelease(InputEvent.BUTTON3_DOWN_MASK);
        robot.waitForIdle();
        robot.keyPress(KeyEvent.VK_CONTROL);
        robot.keyPress(KeyEvent.VK_U);
        robot.keyRelease(KeyEvent.VK_U);
        robot.keyRelease(KeyEvent.VK_CONTROL);
        robot.waitForIdle();
        JPopupMenu popup = label.getComponentPopupMenu();
        if (popup != null && popup.isVisible()) {
            throw new RuntimeException("Popup is visible in wrong internal frame");
        }
    } finally {
        SwingUtilities.invokeAndWait(()->frame.dispose());
    }
}
 
Example 20
Project: incubator-netbeans   File: FilterUtils.java   View source code 5 votes vote down vote up
public KeyStroke registerAction(String actionKey, Action action, ActionMap actionMap, InputMap inputMap) {
    if (!FILTER_ACTION_KEY.equals(actionKey)) return null;
    
    KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_G, InputEvent.CTRL_MASK);
    actionMap.put(actionKey, action);
    inputMap.put(ks, actionKey);

    return ks;
}
 
Example 21
Project: incubator-netbeans   File: TopComponentTest.java   View source code 5 votes vote down vote up
public void testToStringOfDelegateContainsNameOfOriginalAction() throws Exception {
    SaveAction sa = SaveAction.get(SaveAction.class);
    Action a = sa.createContextAwareInstance(Lookup.EMPTY);
    if (a.toString().indexOf("SaveAction") == -1) {
        fail("We need name of the original action:\n" + a.toString());
    }

    SaveAction.cnt = 0;
    CharSequence log = Log.enable("org.netbeans.ui", Level.FINER);
    
    final TopComponent tc = new TopComponent();
    final KeyEvent ke = new KeyEvent(tc, KeyEvent.KEY_PRESSED, System.currentTimeMillis(), KeyEvent.CTRL_MASK, 0, 'S');
    final KeyStroke ks = KeyStroke.getKeyStrokeForEvent(ke);
    MockServices.setServices(MyKM.class);
    SwingUtilities.invokeAndWait(new Runnable() {

        public void run() {
            tc.setActivatedNodes( new Node[0] );
            tc.processKeyBinding(ks, ke, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, true);
        }
        
    });
    
    if (log.toString().indexOf("SaveAction") == -1 
            && SaveAction.cnt == 1 ) { //make sure the action was actually invoked
        fail(log.toString());
    }
}
 
Example 22
Project: incubator-netbeans   File: ListView.java   View source code 5 votes vote down vote up
public Object run() {
    switch (type) {
        case 0:
            NbList.super.paint((Graphics) p1);
            break;
        case 1:
            NbList.super.validateTree();
            break;
        case 2:
            doLayoutImpl();
            break;
        case 3:
            repaintSelection();
            break;
        case 4:
            NbList.super.processEvent((AWTEvent) p1);
            break;
        case 5:
            return NbList.super.getPreferredSize();
        case 6:
            return getToolTipTextImpl((MouseEvent) p1);
        case 7:
            return NbList.super.indexToLocation((Integer) p1);
        case 8:
            return NbList.super.locationToIndex((Point) p1);
        case 9:
            return NbList.super.getSelectedValues();
        case 10:
            Object[] arr = (Object[]) p1;
            return NbList.super.processKeyBinding(
                    (KeyStroke) arr[0],
                    (KeyEvent) arr[1],
                    (Integer) arr[2],
                    (Boolean) arr[3]);                      
        default:
            throw new IllegalStateException("type: " + type);
    }

    return null;
}
 
Example 23
Project: ClipIt   File: ClipboardUtils.java   View source code 5 votes vote down vote up
public static void paste() {
  try {
    Robot robot = new Robot();
    robot.keyPress(KeyEvent.VK_CONTROL);
    robot.keyPress(KeyEvent.VK_V);
    robot.keyRelease(KeyEvent.VK_V);
    robot.keyRelease(KeyEvent.VK_CONTROL);
    // System.out.println("paste...");
  } catch (AWTException e) {
    e.printStackTrace();
  }
}
 
Example 24
Project: JuggleMasterPro   File: MarkJComboBox.java   View source code 5 votes vote down vote up
/**
 * Constructs
 * 
 * @param objPcontrolJFrame
 * @param bytPfilterType
 * @param bolPglobal
 */
public MarkJComboBox(ControlJFrame objPcontrolJFrame, byte bytPfilterType, boolean bolPglobal) {
	this.objGcontrolJFrame = objPcontrolJFrame;
	this.bytGfilterType = bytPfilterType;
	this.bolGglobal = bolPglobal;
	this.setFont(this.objGcontrolJFrame.getFont());
	this.setOpaque(true);
	this.setBackground(Constants.objS_PEN_COLORS_LIGHT_YELLOW_COLOR);
	this.setRenderer(Constants.objS_GRAPHICS_DEFAULT_RENDERER);
	this.setList();
	this.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), KeyEvent.VK_ENTER);
	this.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), KeyEvent.VK_SPACE);
	this.getActionMap()
		.put(	KeyEvent.VK_ENTER,
				new KeysAction(	objPcontrolJFrame,
								bolPglobal ? bytPfilterType == Constants.bytS_BYTE_GLOBAL_LOW_MARK ? KeysAction.bytS_LOW_MARK_J_COMBO_BOX
																									: KeysAction.bytS_HIGH_MARK_J_COMBO_BOX
											: KeysAction.bytS_MARK_J_COMBO_BOX));
	this.getActionMap()
		.put(	KeyEvent.VK_SPACE,
				new KeysAction(	objPcontrolJFrame,
								bolPglobal ? bytPfilterType == Constants.bytS_BYTE_GLOBAL_LOW_MARK ? KeysAction.bytS_LOW_MARK_J_COMBO_BOX
																									: KeysAction.bytS_HIGH_MARK_J_COMBO_BOX
											: KeysAction.bytS_MARK_J_COMBO_BOX,
								KeyEvent.VK_SPACE));
	this.addPopupMenuListener(this);
	this.addActionListener(this);
}
 
Example 25
Project: incubator-netbeans   File: CodeFoldingTestCase.java   View source code 5 votes vote down vote up
protected void collapseAllFolds(EditorOperator editor){
    // hit CTRL Shift -
    JEditorPaneOperator txtOper = editor.txtEditorPane();
    txtOper.pushKey(KeyEvent.VK_SUBTRACT, KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK);
    
    // wait a while
    try {
        Thread.currentThread().sleep(COLLAPSE_EXPAND_DELAY);
    } catch (InterruptedException ex) {
    }
}
 
Example 26
Project: incubator-netbeans   File: JavaEditActionsTest.java   View source code 5 votes vote down vote up
public void testEditActionsTestCase_17() {
    openFileAndSetEditorState("testEditActions", "testEditActions16.pass", 10, 34);
    /// 17 -- test expanding abbreviation
    editor.setCaretPosition(19, 12);
    txtOper.typeKey('s');
    txtOper.typeKey('t');
    txtOper.pressKey(KeyEvent.VK_TAB);
    compareToGoldenFile(editor, "testEditActionsTestCase_1700", "testEditActions17", "testEditActions17");
}
 
Example 27
Project: incubator-netbeans   File: WatchAnnotationProvider.java   View source code 5 votes vote down vote up
@Override
public void keyReleased(KeyEvent e) {
    if (!(e.isAltDown() || e.isAltGraphDown() ||
          e.isControlDown() || e.isMetaDown() ||
          e.isShiftDown())) {

        unsetSelectCursor();
    }
}
 
Example 28
Project: jmt   File: SaveModel.java   View source code 5 votes vote down vote up
/**
 * Defines an <code>Action</code> object with a default
 * description string and default icon.
 */
public SaveModel(Mediator mediator) {
	super("Save", "Save", mediator);
	putValue(SHORT_DESCRIPTION, "Save this model");
	putValue(MNEMONIC_KEY, new Integer(KeyEvent.VK_S));
	putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK));
	setEnabled(false);
}
 
Example 29
Project: incubator-netbeans   File: ContextAwareActionInTopComponentTest.java   View source code 5 votes vote down vote up
public void testGlobalActionDoesNotSurviveFocusChange() throws Exception {
    myGlobalAction.setEnabled( true );
    
    final org.openide.nodes.Node n = new org.openide.nodes.AbstractNode (org.openide.nodes.Children.LEAF);
    tc.setActivatedNodes(new Node[0]);
    
    KeyEvent e = new KeyEvent( tc, KeyEvent.KEY_TYPED, 0, 0, 0 );
    assertTrue( tc.processKeyBinding( KEY_STROKE, e, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, true ) );
    assertTrue( MyContextAwareAction.globalActionWasPerformed );
    assertFalse( MyContextAwareAction.contextActionWasPerformed );
}
 
Example 30
Project: incubator-netbeans   File: ComboTest.java   View source code 5 votes vote down vote up
private void typeKey(final Component target, final int key) throws Exception {
    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            KeyEvent ke = new KeyEvent(target, KeyEvent.KEY_TYPED, System.currentTimeMillis(), 0, KeyEvent.VK_UNDEFINED, (char) key);
            target.dispatchEvent(ke);
        }
    });
    sleep();
}
 
Example 31
Project: incubator-netbeans   File: FixImportsTest.java   View source code 5 votes vote down vote up
public void testRemoveAndAdd() {
    Node pn = new ProjectsTabOperator().getProjectRootNode(TEST_PROJECT_NAME);
    pn.select();
    
    Node n = new Node(pn, org.netbeans.jellytools.Bundle.getString(
            "org.netbeans.modules.java.j2seproject.Bundle",
            "NAME_src.dir")+"|"+TEST_PACKAGE_NAME+"|"
            +TEST_CLASS_NAME);
    n.select();
    new OpenAction().perform();
    EditorOperator editor = new EditorOperator(TEST_CLASS_NAME);
    try {
        editor.insert("import java.util.Date;\n", 41, 1);
        editor.insert("List m;\n", 47, 1);
        Utilities.takeANap(100);
        MainWindowOperator.getDefault().pushKey(KeyEvent.VK_I,
                KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK);
        
        FixAllImports fio = new FixAllImports();
        fio.cbRemoveUnusedImports().changeSelection(true);
        fio.ok();
        Utilities.takeANap(500);
        assertFalse("Import is not removed",editor.getText().contains("import java.util.Date;"));
        assertTrue("Import is not added",editor.getText().contains("import java.util.List;"));
    } finally {
        editor.close(false);
    }
    
}
 
Example 32
Project: incubator-netbeans   File: CompletionLayout.java   View source code 5 votes vote down vote up
public void processKeyEvent(KeyEvent evt) {
    if (isVisible()) {
        Object actionMapKey = completionScrollPane.getInputMap().get(
                KeyStroke.getKeyStrokeForEvent(evt));
        
        if (actionMapKey != null) {
            Action action = completionScrollPane.getActionMap().get(actionMapKey);
            if (action != null) {
                action.actionPerformed(new ActionEvent(completionScrollPane, 0, null));
                evt.consume();
            }
        }
    }
}
 
Example 33
Project: jvb   File: DefaultSwingInputProvider.java   View source code 5 votes vote down vote up
@Override
public boolean postProcessKeyEvent(KeyEvent e) {
    Inputs input = keyCodeToInput(e.getKeyCode(), e.getKeyLocation());
    if (input == null) {
        return false;
    }
    if (e.getID() == KeyEvent.KEY_PRESSED) {
        status |= intBit(input.offset());
        return true;
    } else if (e.getID() == KeyEvent.KEY_RELEASED) {
        status &= ~intBit(input.offset());
        return true;
    }
    return false;
}
 
Example 34
Project: ProyectoPacientes   File: JDagregar.java   View source code 5 votes vote down vote up
private void direccionKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_direccionKeyPressed
    // TODO add your handling code here:
    if(evt.getKeyCode() == KeyEvent.VK_ENTER)
    {
        this.telefono.requestFocus();
    }
}
 
Example 35
Project: jdk8u-jdk   File: WToolkit.java   View source code 5 votes vote down vote up
@Override
public boolean getLockingKeyState(int key) {
    if (! (key == KeyEvent.VK_CAPS_LOCK || key == KeyEvent.VK_NUM_LOCK ||
           key == KeyEvent.VK_SCROLL_LOCK || key == KeyEvent.VK_KANA_LOCK)) {
        throw new IllegalArgumentException("invalid key for Toolkit.getLockingKeyState");
    }
    return getLockingKeyStateNative(key);
}
 
Example 36
Project: jdk8u-jdk   File: bug8032878.java   View source code 5 votes vote down vote up
private void runTest() throws Exception {
    realSync();
    // Select 'one'
    Util.hitKeys(robot, KeyEvent.VK_TAB);
    realSync();
    Util.hitKeys(robot, KeyEvent.VK_1);
    Util.hitKeys(robot, KeyEvent.VK_2);
    Util.hitKeys(robot, KeyEvent.VK_3);
    Util.hitKeys(robot, KeyEvent.VK_ENTER);
    realSync();
}
 
Example 37
Project: jdk8u-jdk   File: WTextFieldPeer.java   View source code 5 votes vote down vote up
@Override
public boolean handleJavaKeyEvent(KeyEvent e) {
    switch (e.getID()) {
       case KeyEvent.KEY_TYPED:
           if ((e.getKeyChar() == '\n') && !e.isAltDown() && !e.isControlDown()) {
                postEvent(new ActionEvent(target, ActionEvent.ACTION_PERFORMED,
                                          getText(), e.getWhen(), e.getModifiers()));
                return true;
           }
       break;
    }
    return false;
}
 
Example 38
Project: openjdk-jdk10   File: MouseComboBoxTest.java   View source code 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    robot = new Robot();
    robot.setAutoDelay(50);

    UIManager.setLookAndFeel(new MetalLookAndFeel());
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            createAndShowGUI();
        }
    });
    robot.waitForIdle();

    for (int i = 0; i < items.length; i++) {
        // Open popup
        robot.keyPress(KeyEvent.VK_DOWN);
        robot.keyRelease(KeyEvent.VK_DOWN);
        robot.waitForIdle();

        Point point = getItemPointToClick(i);
        robot.mouseMove(point.x, point.y);
        robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
        robot.waitForIdle();

        if (i != getSelectedIndex()) {
            throw new RuntimeException("Test Failed! Incorrect value of selected index = " + getSelectedIndex() +
                    ", expected value = " + i);
        }
    }
}
 
Example 39
Project: Pixie   File: UserConfigs.java   View source code 5 votes vote down vote up
/**
 * Handles the keys which have to be enabled all the time in the frame.
 */
private void dispatchKeyGeneral(KeyEvent e) {
    int eventId = e.getID();
    int key = e.getKeyCode();

    if (eventId == KeyEvent.KEY_PRESSED) {

        switch (key) {

            case KeyEvent.VK_ESCAPE:
                cancelWindow();
                break;

            case KeyEvent.VK_ENTER:
                // if the textfield id the focus owner, do not save the object
                if (jFTFObjAlphaVal.isFocusOwner() || jFTFDPIValue.isFocusOwner()) {
                    break;
                }

                savePreferences();
                break;

            default:
                // do nothing
                break;
        }
    }
}
 
Example 40
Project: OpenDA   File: PlotBox.java   View source code 5 votes vote down vote up
public void keyReleased(KeyEvent e) {
    int keycode = e.getKeyCode();
    switch(keycode) {
    case KeyEvent.VK_CONTROL:
        _control = false;
        break;
    case KeyEvent.VK_SHIFT:
        _shift = false;
        break;
    default:
        // None
    }
}