當前位置: 首頁>>代碼示例>>Java>>正文


Java KeyEvent.getSource方法代碼示例

本文整理匯總了Java中java.awt.event.KeyEvent.getSource方法的典型用法代碼示例。如果您正苦於以下問題:Java KeyEvent.getSource方法的具體用法?Java KeyEvent.getSource怎麽用?Java KeyEvent.getSource使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.awt.event.KeyEvent的用法示例。


在下文中一共展示了KeyEvent.getSource方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: keyPressed

import java.awt.event.KeyEvent; //導入方法依賴的package包/類
/**
 *  Description of the Method
 *
 * @param  evt  Description of the Parameter
 */
public void keyPressed(KeyEvent evt) {
	Object src = evt.getSource();
	int code = evt.getKeyCode();

	//changed by saruta
	// if (code == KeyEvent.VK_ESCAPE)
	//	actionPerformed(new ActionEvent(cancelButton, 0, cancelButton.getActionCommand()));

	if (src == fileList) {
		if (code == KeyEvent.VK_SPACE || code == KeyEvent.VK_ENTER) {
			File[] arr = getSelectedFiles();
			if (arr.length == 1 && arr[0].isDirectory()) {
				fileChooser.setCurrentDirectory(arr[0]);
			}
			evt.consume();
			//filenameTextField.setText(arr[0].getPath());
		}
		//if (code == KeyEvent.VK_ENTER) {
		//	fileList.getSelectionModel().clearSelection();
		//	actionPerformed(new ActionEvent(okButton, 0, "enter"));
		//}
	}
}
 
開發者ID:SarutaSan72,項目名稱:Yass,代碼行數:29,代碼來源:FileChooserFixer.java

示例2: keyPressed

import java.awt.event.KeyEvent; //導入方法依賴的package包/類
/**
 * Wcisnieto jakiś przycisk na kontrolkach, w tym przypadku może to być
 * jakiś skrót klawiaturowy
 *
 * @param arg0
 */
@Override
public void keyPressed(KeyEvent arg0) {
    if (arg0.getSource() instanceof JTextField) // dla pol tekstowych nie dziala
    {
        return;
    }
    // przejscie po skrotach lokalnych (globalne zostaną obsłużone przez swinga, gdyż
    // jest to niewidzialne menu)
    for (ShortCut shortCut : viewScopeShortCuts) {
        // wyszykiwanie skrótu
        if (arg0.getModifiers() == shortCut.getModifiers() && arg0.getKeyCode() == shortCut.getKeyCode()) {
            arg0.consume();      // konsumcja zdarzenia
            shortCut.doAction(); // wywołanie akcji związanej ze skrótem
            break;
        }
    }
}
 
開發者ID:CLARIN-PL,項目名稱:WordnetLoom,代碼行數:24,代碼來源:AbstractViewUI.java

示例3: keyTyped

import java.awt.event.KeyEvent; //導入方法依賴的package包/類
@Override
public void keyTyped(KeyEvent ke) {             
   if(ke.getSource() == frame.getjList1()) {
        if(ke.getKeyCode() == KeyEvent.VK_UP ||
            ke.getKeyCode() == KeyEvent.VK_DOWN ||
            ke.getKeyCode() == KeyEvent.VK_ENTER ||
            ke.getKeyCode() == KeyEvent.VK_CONTROL) {                
            return;
        } else {
            int selection = frame.getjList1().getSelectedIndex();
            for(int i = 0; i < pane.getKeyListeners().length; ++i) {
            if(pane.getKeyListeners()[i] != this) 
                    pane.getKeyListeners()[i].keyTyped(ke);
            }
            giveMenuOptions();
            ke.consume();
            frame.getjList1().setSelectedIndex(selection);
        }            
        
   }
}
 
開發者ID:Skypr,項目名稱:BEAST,代碼行數:22,代碼來源:AutocompletionController.java

示例4: keyPressed

import java.awt.event.KeyEvent; //導入方法依賴的package包/類
@Override
public void keyPressed(KeyEvent ke) {
	
	int keyCode = ke.getKeyCode();
	Object keSource = ke.getSource();
	JTextField jTextField = (JTextField) keSource;;
	int caretPos = jTextField.getCaretPosition();
	int textLength = jTextField.getText().length();
	
	if(keyCode == KeyEvent.VK_ESCAPE){
		// Due to a java bug, the callback method is not called automatically when pressing escape.
		cancelCellEditing();
	} else if(keyCode == KeyEvent.VK_ENTER || keyCode == KeyEvent.VK_TAB){
		// Remember which key was used to confirm editing
		confirmationKey = keyCode;
	} else if(keyCode==KeyEvent.VK_RIGHT && caretPos==textLength){
		confirmationKey = keyCode;
		stopCellEditing();
	} else if(keyCode==KeyEvent.VK_LEFT && caretPos==0){
		confirmationKey = keyCode;
		stopCellEditing();
	}
}
 
開發者ID:EnFlexIT,項目名稱:AgentWorkbench,代碼行數:24,代碼來源:BasicCellEditor.java

示例5: keyReleased

import java.awt.event.KeyEvent; //導入方法依賴的package包/類
@Override
public void keyReleased(KeyEvent e) {
    if(e.getKeyCode() != KeyEvent.VK_ENTER) {
        return;
    }
    if(e.getSource() == panel.productList ||
       e.getSource() == panel.componentList ||
       e.getSource() == panel.versionList ||
       e.getSource() == panel.statusList ||
       e.getSource() == panel.resolutionList ||
       e.getSource() == panel.priorityList ||
       e.getSource() == panel.changedList)
    {
        onRefresh();
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:17,代碼來源:QueryController.java

示例6: keyPressed

import java.awt.event.KeyEvent; //導入方法依賴的package包/類
public void keyPressed(KeyEvent e) {
    int keyc = e.getKeyCode();
    if (keyc == KeyEvent.VK_UP || keyc == KeyEvent.VK_DOWN
            || keyc == KeyEvent.VK_LEFT || keyc == KeyEvent.VK_RIGHT) {
        // System.err.println("arrow key released");
        ActionEvent action = new ActionEvent(e.getSource(),
                ActionEvent.ACTION_PERFORMED, InputGUI.GRAMSEL);
        g.actionPerformed(action);
    }
}
 
開發者ID:spetitjean,項目名稱:TuLiPA-frames,代碼行數:11,代碼來源:InputGUI.java

示例7: keyReleased

import java.awt.event.KeyEvent; //導入方法依賴的package包/類
@Override
    public void keyReleased(KeyEvent e) {
        int keyCode = e.getKeyCode();
        if (keyCode == KeyEvent.VK_UP || keyCode == KeyEvent.VK_DOWN) {
            JTree tree = (JTree) e.getSource();
            int row = tree.getSelectionRows()[0];
            TreePath path = tree.getSelectionPath();
            if (path != null) {
                CheckNode node = (CheckNode) path.getLastPathComponent();

                Object o = node.getUserObject();
                if (o instanceof TreeElement) {
                    o = ((TreeElement) o).getUserObject();
                    if (o instanceof RefactoringElement) {
                        openDiff(node);
                    }
//                    else if (o instanceof FileObject) {
//                        tree.expandPath(path);
//                        TreePath pathForRow = tree.getPathForRow(row + 1);
//                        CheckNode lastPathComponent = (CheckNode) pathForRow.getLastPathComponent();
//                        Object userObject = lastPathComponent.getUserObject();
//                        if (userObject instanceof TreeElement) {
//                            Object refElement = ((TreeElement) userObject).getUserObject();
//                            if (refElement instanceof RefactoringElement) {
//                                openDiff(lastPathComponent);
//                            }
//                        }
//                    }
                }
            }
        }
    }
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:33,代碼來源:CheckNodeListener.java

示例8: keyPressed

import java.awt.event.KeyEvent; //導入方法依賴的package包/類
public void keyPressed(KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_SPACE || e.getKeyCode() == KeyEvent.VK_ENTER ) {

        if ( e.getSource() instanceof JTree ) {
            JTree tree = (JTree) e.getSource();
            TreePath path = tree.getSelectionPath();

            if ( toggle( path )) {
                e.consume();
            }
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:14,代碼來源:FmtSpaces.java

示例9: keyPressed

import java.awt.event.KeyEvent; //導入方法依賴的package包/類
public void keyPressed(KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_SPACE) {

        if ( e.getSource() instanceof JTree ) {
            JTree tree = (JTree) e.getSource();
            TreePath path = tree.getSelectionPath();

            if ( toggle( path )) {
                e.consume();
            }
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:14,代碼來源:HintsPanelLogic.java

示例10: keyPressed

import java.awt.event.KeyEvent; //導入方法依賴的package包/類
@Override
public void keyPressed(KeyEvent event) {
    // listens for enter key press on button
    if (event.getSource() == this && event.getModifiers() == 0 && event.getKeyCode() == KeyEvent.VK_ENTER) {
        event.consume();
        doClick();
    }
}
 
開發者ID:CLARIN-PL,項目名稱:WordnetLoom,代碼行數:9,代碼來源:MButton.java

示例11: keyPressed

import java.awt.event.KeyEvent; //導入方法依賴的package包/類
public void keyPressed(KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_SPACE ) {
        
        if ( e.getSource() instanceof JTree ) {
            JTree tree = (JTree) e.getSource();
            TreePath path = tree.getSelectionPath();

            if ( toggle( path )) {
                e.consume();
                repaint(); //XXX
            }
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:15,代碼來源:CheckTreeView.java

示例12: keyPressed

import java.awt.event.KeyEvent; //導入方法依賴的package包/類
@Override
public void keyPressed(KeyEvent ke) {
    if(ke.getSource() == frame.getjList1()) {
        if(ke.getKeyCode() == KeyEvent.VK_UP ||
            ke.getKeyCode() == KeyEvent.VK_DOWN) {                
            return;
        } else if(ke.getKeyCode() == KeyEvent.VK_ESCAPE) {
            frame.setVisible(false);
        } else if(ke.getKeyCode() == KeyEvent.VK_ENTER) {
            String s = frame.getjList1().getSelectedValue();
            if(s != null) choseCompletion(s);
            frame.setVisible(false);
        } 
    }
}
 
開發者ID:Skypr,項目名稱:BEAST,代碼行數:16,代碼來源:AutocompletionController.java

示例13: processKeyEvent

import java.awt.event.KeyEvent; //導入方法依賴的package包/類
@Override
public void processKeyEvent(KeyEvent evt) {
    if (evt.getID() == KeyEvent.KEY_TYPED) {
        if (evt.getKeyChar() == '.') { // NOI18N
            Completion.get().hideDocumentation();
            JTextComponent component = (JTextComponent) evt.getSource();
            int caretOffset = component.getSelectionEnd();
            substituteText(component, substitutionOffset, caretOffset - substitutionOffset, Character.toString(evt.getKeyChar()));
            Completion.get().showCompletion();
            evt.consume();
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:14,代碼來源:HibernateCompletionItem.java

示例14: keyReleased

import java.awt.event.KeyEvent; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
@Override
public void keyReleased(final KeyEvent e) {
    final Object source = e.getSource();

    if (m_gui.isClassField(source)) {
        if (e.getKeyCode() == KeyEvent.VK_ENTER) {
            actionUserAddedClass();
        }
    }
}
 
開發者ID:knime,項目名稱:knime-activelearning,代碼行數:14,代碼來源:ActiveLearnLoopEndNodeViewListener.java

示例15: dispatchKeyEvent

import java.awt.event.KeyEvent; //導入方法依賴的package包/類
public boolean dispatchKeyEvent(KeyEvent e) {
    if (skippingEvents || e.isConsumed()) return false;
    
    if (e.getID() == KeyEvent.KEY_PRESSED && e.getKeyCode() == KeyEvent.VK_ESCAPE)
        if (SwingUtilities.getRootPane(this) != e.getSource()) { // Closing JPopupMenu using the ESC key
            e.consume();
            if (DEBUG) System.err.println(">>> Closed by ESC"); // NOI18N
            ProfilerPopup.this.hide();
            return true;
        }
    
    return false;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:14,代碼來源:ProfilerPopup.java


注:本文中的java.awt.event.KeyEvent.getSource方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。