Java Code Examples for java.awt.event.KeyEvent

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project freemind, under directory /freemind/freemind/preferences/layout/.

Source file: GrabKeyDialog.java

  18 
vote

protected void processKeyEvent(KeyEvent _evt){
  if ((getModifierMask() & _evt.getModifiers()) != 0) {
    KeyEvent evt=new KeyEvent(_evt.getComponent(),_evt.getID(),_evt.getWhen(),~getModifierMask() & _evt.getModifiers(),_evt.getKeyCode(),_evt.getKeyChar(),_evt.getKeyLocation());
    processKeyEvent(evt);
    if (evt.isConsumed()) {
      _evt.consume();
    }
    return;
  }
  KeyEvent evt=KeyEventWorkaround.processKeyEvent(_evt);
  if (debugBuffer != null) {
    debugBuffer.insert(debugBuffer.getLength(),"Event " + GrabKeyDialog.toString(_evt) + (evt == null ? " filtered\n" : " passed\n"));
  }
  if (evt == null)   return;
  evt.consume();
  KeyEventTranslator.Key key=KeyEventTranslator.translateKeyEvent(evt);
  if (key == null)   return;
  if (debugBuffer != null) {
    debugBuffer.insert(debugBuffer.getLength(),"==> Translated to " + key + "\n");
  }
  StringBuffer keyString=new StringBuffer();
  if (key.modifiers != null)   keyString.append(key.modifiers).append(' ');
  if (key.input == ' ')   keyString.append("SPACE");
 else   if (key.input != '\0')   keyString.append(key.input);
 else {
    String symbolicName=getSymbolicName(key.key);
    if (symbolicName == null)     return;
    keyString.append(symbolicName);
  }
  setText(keyString.toString());
  if (debugBuffer == null)   updateAssignedTo(keyString.toString());
}
 

Example 2

From project beanmill_1, under directory /src/main/java/com/traxel/lumbermill/event/.

Source file: TableView.java

  17 
vote

/** 
 * ------------------------------------- Instance Initialization -------------------------------------
 * @param log        DOCUMENT ME!
 * @param filterSet  DOCUMENT ME!
 * @param columnSet  DOCUMENT ME!
 */
public TableView(final Log log,final FilterSet filterSet,final ColumnSet columnSet){
  super(new Table(log,filterSet,columnSet));
  hotkeyPressed=false;
  getModel().addTableModelListener(new Unselector());
  setColumnModel(getTable().getColumnSet());
  setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
  Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener(){
    @Override public void eventDispatched(    final AWTEvent event){
      if (LOG.isDebugEnabled()) {
        LOG.debug("received event: " + event);
      }
      final KeyEvent keyEvent=(KeyEvent)event;
switch (keyEvent.getID()) {
case KeyEvent.KEY_TYPED:
{
          return;
        }
case KeyEvent.KEY_PRESSED:
{
        if (keyEvent.getKeyCode() == NbPreferences.forModule(TableView.class).getInt(NetbeansPanel.PROP_TOOLTIP_HK,-1)) {
          hotkeyPressed=true;
        }
        return;
      }
case KeyEvent.KEY_RELEASED:
{
      if (keyEvent.getKeyCode() == NbPreferences.forModule(TableView.class).getInt(NetbeansPanel.PROP_TOOLTIP_HK,-1)) {
        hotkeyPressed=false;
      }
      return;
    }
default :
{
    return;
  }
}
}
}
,AWTEvent.KEY_EVENT_MASK);
}
 

Example 3

From project ceres, under directory /ceres-ui/src/test/java/com/bc/ceres/swing/figure/.

Source file: AbstractInteractorTest.java

  17 
vote

public void testEscKeyPressedInvokesCancel(){
  AbstractInteractor interaction=new AbstractInteractor(){
  }
;
  MyInteractorListener listener=new MyInteractorListener();
  interaction.addListener(listener);
  JMenu source=new JMenu();
  interaction.keyTyped(new KeyEvent(source,0,0,0,' ',' '));
  assertEquals("",listener.trace);
  interaction.keyTyped(new KeyEvent(source,0,0,0,27,(char)27));
  assertEquals("c;",listener.trace);
  interaction.keyTyped(new KeyEvent(source,0,0,0,'A','A'));
  assertEquals("c;",listener.trace);
}
 

Example 4

From project codjo-data-process, under directory /codjo-data-process-common/src/main/java/net/codjo/dataprocess/common/eventsbinder/annotations/managers/.

Source file: OnKeyAnnotationManager.java

  17 
vote

public boolean checkEvent(EventObject eventObject,String methodCalled){
  boolean keyCharOk=false;
  boolean keyCodeOk=false;
  boolean modifiersOk=false;
  boolean methodOk=false;
  KeyEvent keyEvent=(KeyEvent)eventObject;
  if (onKey.keyChar() == 0 || keyEvent.getKeyChar() == onKey.keyChar()) {
    keyCharOk=true;
  }
  if (onKey.keyCode() == -1 || keyEvent.getKeyCode() == onKey.keyCode()) {
    keyCodeOk=true;
  }
  if (onKey.modifiers() == -1 || keyEvent.getModifiers() == onKey.modifiers()) {
    modifiersOk=true;
  }
switch (onKey.eventType()) {
case ALL:
    methodOk=true;
  break;
case PRESSED:
methodOk="keyPressed".equals(methodCalled);
break;
case RELEASED:
methodOk="keyReleased".equals(methodCalled);
break;
case TYPED:
methodOk="keyTyped".equals(methodCalled);
}
return keyCharOk && keyCodeOk && modifiersOk&& methodOk;
}
 

Example 5

From project engine, under directory /main/com/midtro/platform/.

Source file: State.java

  17 
vote

/** 
 * Runs the input events that have been queued since the last frame.
 * @param queue The queue of input events to handle.
 * @param app The application.
 */
public final void handleInput(Queue<InputEvent> queue,Application app){
  entry:   while (!queue.isEmpty()) {
    final InputEvent event=queue.poll();
    if (event instanceof MouseEvent) {
      final MouseEvent mouseEvent=(MouseEvent)event;
      for (      final MouseInjector injector : app.getMouseInjectors()) {
        if (injector.handleMouseEvent(mouseEvent)) {
          continue entry;
        }
      }
      handleMouseEvent(mouseEvent,app);
    }
    if (event instanceof KeyEvent) {
      final KeyEvent keyEvent=(KeyEvent)event;
      for (      final KeyInjector injector : app.getKeyInjectors()) {
        if (injector.handleKeyEvent(keyEvent)) {
          continue entry;
        }
      }
      handleKeyEvent(keyEvent,app);
    }
  }
}
 

Example 6

From project Haven-and-Hearth-client-modified-by-Ender, under directory /src/haven/.

Source file: HavenPanel.java

  17 
vote

void dispatch(){
synchronized (events) {
    InputEvent e=null;
    while ((e=events.poll()) != null) {
      if (e instanceof MouseEvent) {
        MouseEvent me=(MouseEvent)e;
        if (me.getID() == MouseEvent.MOUSE_PRESSED) {
          ui.mousedown(me,new Coord(me.getX(),me.getY()),me.getButton());
        }
 else         if (me.getID() == MouseEvent.MOUSE_RELEASED) {
          ui.mouseup(me,new Coord(me.getX(),me.getY()),me.getButton());
        }
 else         if (me.getID() == MouseEvent.MOUSE_MOVED || me.getID() == MouseEvent.MOUSE_DRAGGED) {
          mousepos=new Coord(me.getX(),me.getY());
          ui.mousemove(me,mousepos);
        }
 else         if (me instanceof MouseWheelEvent) {
          ui.mousewheel(me,new Coord(me.getX(),me.getY()),((MouseWheelEvent)me).getWheelRotation());
        }
      }
 else       if (e instanceof KeyEvent) {
        KeyEvent ke=(KeyEvent)e;
        if (ke.getID() == KeyEvent.KEY_PRESSED) {
          ui.keydown(ke);
        }
 else         if (ke.getID() == KeyEvent.KEY_RELEASED) {
          ui.keyup(ke);
        }
 else         if (ke.getID() == KeyEvent.KEY_TYPED) {
          ui.type(ke);
        }
      }
      ui.lastevent=System.currentTimeMillis();
    }
  }
}
 

Example 7

From project addis, under directory /application/src/main/java/org/drugis/addis/gui/wizard/.

Source file: IndicationAndNameInputPanel.java

  16 
vote

private static void updateBorder(final JTextField nameInput,final Border border,AnalysisWizardPresentation pm){
  if (!pm.getNameValidModel().getValue()) {
    nameInput.setBorder(BorderFactory.createLineBorder(Color.RED,2));
    if (pm.getNameModel().getValue() == null || pm.getNameModel().getValue().isEmpty()) {
      nameInput.setToolTipText("An analysis must have a name, please provide one.");
    }
 else {
      nameInput.setToolTipText("An analysis with that name already exists, please change it.");
    }
    nameInput.dispatchEvent(new KeyEvent(nameInput,KeyEvent.KEY_PRESSED,0,KeyEvent.CTRL_MASK,KeyEvent.VK_F1,KeyEvent.CHAR_UNDEFINED));
  }
 else {
    nameInput.setToolTipText("");
    nameInput.setBorder(border);
  }
}
 

Example 8

From project alg-vis, under directory /src/algvis/aatree/.

Source file: AAButtons.java

  15 
vote

@Override public void otherButtons(JPanel P){
  B23=new ICheckBox("mode23",false);
  B23.setMnemonic(KeyEvent.VK_2);
  B23.addActionListener(this);
  P.add(B23);
}
 

Example 9

From project autopsy, under directory /HashDatabase/src/org/sleuthkit/autopsy/hashdatabase/.

Source file: HashDbManagementPanel.java

  15 
vote

private void hashSetTableKeyPressed(java.awt.event.KeyEvent evt){
  if (evt.getKeyCode() == KeyEvent.VK_DELETE) {
    int selected=getSelection();
    HashDbXML xmlHandle=HashDbXML.getCurrent();
    if (xmlHandle.getNSRLSet() != null) {
      if (selected == 0) {
        HashDbXML.getCurrent().removeNSRLSet();
      }
 else {
        HashDbXML.getCurrent().removeKnownBadSetAt(selected - 1);
      }
    }
 else {
      HashDbXML.getCurrent().removeKnownBadSetAt(selected);
    }
  }
  hashSetTableModel.resync();
}
 

Example 10

From project Battlepath, under directory /src/interaction/.

Source file: Input.java

  15 
vote

@Override public void keyPressed(KeyEvent arg0){
  int c=arg0.getKeyCode();
  if (!pressedKeys.containsKey(c))   pressedKeys.put((Integer)c,null);
 else {
    try {
      pressedKeys.get(c).cancel();
    }
 catch (    java.lang.NullPointerException e) {
    }
  }
}
 

Example 11

From project BDSup2Sub, under directory /src/main/java/bdsup2sub/gui/edit/.

Source file: EditDialogView.java

  15 
vote

private JButton getJButtonPrev(){
  if (jButtonPrev == null) {
    jButtonPrev=new JButton();
    jButtonPrev.setText("  <  ");
    jButtonPrev.setMnemonic(KeyEvent.VK_LEFT);
    jButtonPrev.setToolTipText("Lose changes and skip to previous frame");
  }
  return jButtonPrev;
}
 

Example 12

From project BioMAV, under directory /ParrotSim/Java/src/nl/ru/ai/projects/parrot/dronecontrol/manualcontrol/.

Source file: Control.java

  15 
vote

public void keyPressed(KeyEvent e){
  System.out.println("Typed " + e.getKeyCode());
switch (e.getKeyCode()) {
case 37:
    left=true;
  break;
case 38:
up=true;
break;
case 39:
right=true;
break;
case 40:
down=true;
break;
case 88:
xButton=true;
break;
case 90:
zButton=true;
break;
case 65:
aButton=true;
break;
case 68:
dButton=true;
break;
default :
;
break;
}
}
 

Example 13

From project BMach, under directory /src/jsyntaxpane/actions/gui/.

Source file: ComboCompletionDialog.java

  15 
vote

/** 
 * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of this method is always regenerated by the Form Editor.
 */
@SuppressWarnings("unchecked") private void initComponents(){
  jTxtItem=new javax.swing.JTextField();
  jScrollPane1=new javax.swing.JScrollPane();
  jLstItems=new javax.swing.JList();
  setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
  setResizable(false);
  setUndecorated(true);
  jTxtItem.setBorder(null);
  jTxtItem.addKeyListener(new java.awt.event.KeyAdapter(){
    public void keyPressed(    java.awt.event.KeyEvent evt){
      jTxtItemKeyPressed(evt);
    }
  }
);
  jLstItems.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
  jLstItems.setFocusable(false);
  jLstItems.addMouseListener(new java.awt.event.MouseAdapter(){
    public void mouseClicked(    java.awt.event.MouseEvent evt){
      jLstItemsMouseClicked(evt);
    }
  }
);
  jScrollPane1.setViewportView(jLstItems);
  javax.swing.GroupLayout layout=new javax.swing.GroupLayout(getContentPane());
  getContentPane().setLayout(layout);
  layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(jTxtItem,javax.swing.GroupLayout.DEFAULT_SIZE,375,Short.MAX_VALUE).addComponent(jScrollPane1,javax.swing.GroupLayout.DEFAULT_SIZE,375,Short.MAX_VALUE));
  layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addComponent(jTxtItem,javax.swing.GroupLayout.PREFERRED_SIZE,javax.swing.GroupLayout.DEFAULT_SIZE,javax.swing.GroupLayout.PREFERRED_SIZE).addGap(0,0,0).addComponent(jScrollPane1,javax.swing.GroupLayout.DEFAULT_SIZE,111,Short.MAX_VALUE)));
  pack();
}
 

Example 14

From project Calendar-Application, under directory /com/toedter/calendar/.

Source file: JDayChooser.java

  15 
vote

/** 
 * JDayChooser is the KeyListener for all day buttons. (Added by Thomas Schaefer and modified by Austin Moore)
 * @param e the KeyEvent
 */
public void keyPressed(KeyEvent e){
  int offset=(e.getKeyCode() == KeyEvent.VK_UP) ? (-7) : ((e.getKeyCode() == KeyEvent.VK_DOWN) ? (+7) : ((e.getKeyCode() == KeyEvent.VK_LEFT) ? (-1) : ((e.getKeyCode() == KeyEvent.VK_RIGHT) ? (+1) : 0)));
  int newDay=getDay() + offset;
  if ((newDay >= 1) && (newDay <= calendar.getMaximum(Calendar.DAY_OF_MONTH))) {
    setDay(newDay);
  }
}
 

Example 15

From project Clotho-Core, under directory /ClothoApps/PluginManager/src/org/clothocore/tool/pluginmanager/gui/.

Source file: ChoosePreferredViewers.java

  15 
vote

@Override public void keyPressed(KeyEvent e){
  int keyCode=e.getKeyCode();
switch (keyCode) {
case KeyEvent.VK_LEFT:
case KeyEvent.VK_UP:
    scrollAndAnimateBy(-1);
  break;
case KeyEvent.VK_RIGHT:
case KeyEvent.VK_DOWN:
scrollAndAnimateBy(1);
break;
case KeyEvent.VK_END:
scrollBy(avatars.size() - avatarIndex - 1);
break;
case KeyEvent.VK_HOME:
scrollBy(-avatarIndex - 1);
break;
case KeyEvent.VK_PAGE_UP:
scrollAndAnimateBy(-avatarAmount / 2);
break;
case KeyEvent.VK_PAGE_DOWN:
scrollAndAnimateBy(avatarAmount / 2);
break;
}
}
 

Example 16

From project CloudReports, under directory /src/main/java/cloudreports/gui/customers/.

Source file: NewCustomer.java

  15 
vote

/** 
 * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of this method is always regenerated by the Form Editor.
 */
@SuppressWarnings("unchecked") private void initComponents(){
  jLabel1=new javax.swing.JLabel();
  textField=new javax.swing.JTextField();
  cancelButton=new javax.swing.JButton();
  okButton=new javax.swing.JButton();
  setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
  setTitle("New Customer");
  setModal(true);
  setResizable(false);
  jLabel1.setText("New customer's name:");
  textField.addKeyListener(new java.awt.event.KeyAdapter(){
    public void keyPressed(    java.awt.event.KeyEvent evt){
      textFieldKeyPressed(evt);
    }
  }
);
  cancelButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cloudreports/gui/resources/cancel.png")));
  cancelButton.setText("Cancel");
  cancelButton.addActionListener(new java.awt.event.ActionListener(){
    public void actionPerformed(    java.awt.event.ActionEvent evt){
      cancelButtonActionPerformed(evt);
    }
  }
);
  okButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/cloudreports/gui/resources/ok.png")));
  okButton.setText("OK");
  okButton.addActionListener(new java.awt.event.ActionListener(){
    public void actionPerformed(    java.awt.event.ActionEvent evt){
      okButtonActionPerformed(evt);
    }
  }
);
  javax.swing.GroupLayout layout=new javax.swing.GroupLayout(getContentPane());
  getContentPane().setLayout(layout);
  layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addComponent(jLabel1).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(textField,javax.swing.GroupLayout.DEFAULT_SIZE,219,Short.MAX_VALUE)).addGroup(javax.swing.GroupLayout.Alignment.TRAILING,layout.createSequentialGroup().addComponent(okButton).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(cancelButton))).addContainerGap()));
  layout.linkSize(javax.swing.SwingConstants.HORIZONTAL,new java.awt.Component[]{cancelButton,okButton});
  layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel1).addComponent(textField,javax.swing.GroupLayout.PREFERRED_SIZE,javax.swing.GroupLayout.DEFAULT_SIZE,javax.swing.GroupLayout.PREFERRED_SIZE)).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(cancelButton).addComponent(okButton)).addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,Short.MAX_VALUE)));
  pack();
}
 

Example 17

From project Codeable_Objects, under directory /SoftObjects/src/com/ui/.

Source file: ScreenManager.java

  15 
vote

public void keyEvent(KeyEvent event){
  int keyCode=event.getKeyCode();
switch (event.getID()) {
case KeyEvent.KEY_PRESSED:
    this.keyPressed(keyCode);
  break;
case KeyEvent.KEY_RELEASED:
this.keyReleased(keyCode);
break;
}
}
 

Example 18

From project codjo-segmentation, under directory /codjo-segmentation-gui/src/main/java/net/codjo/segmentation/gui/editor/.

Source file: EditorMainPanelLogic.java

  15 
vote

@Override public void keyPressed(KeyEvent event){
  if (event.getKeyChar() == KeyEvent.VK_ENTER) {
    Object obj=((JList)event.getSource()).getSelectedValue();
    String value;
    if (obj instanceof FunctionHelp) {
      value=((FunctionHelp)obj).getFunctionName();
    }
 else {
      value=obj.toString();
    }
    JTextPane expression=editorMainPanelGui.getExpressionTextPane();
    try {
      expression.getDocument().insertString(expression.getCaretPosition(),value,defaultAttributeSet);
    }
 catch (    Exception ex) {
      APP.error(ex.getMessage(),ex);
    }
  }
}
 

Example 19

From project codjo-standalone-common, under directory /src/main/java/net/codjo/utils/sql/.

Source file: SqlRequetor.java

  15 
vote

/** 
 * Description of the Method
 * @param e Description of the Parameter
 */
void textFieldValueKeyReleased(KeyEvent e){
  if (!sqlListModel.isEmpty()) {
    req.setValue(textFieldValue.getText(),getIndex());
    updateSqlRequest();
  }
}
 

Example 20

From project contribution_eevolution_smart_browser, under directory /client/src/org/compiere/apps/.

Source file: APanel.java

  15 
vote

/** 
 * Removes the default KeyStroke action for the up/down keys and adds switch line actions.
 */
private void initSwitchLineAction(){
  aSwitchLinesDownAction=new SwitchAction("switchLinesDown",KeyStroke.getKeyStroke(KeyEvent.VK_DOWN,Event.SHIFT_MASK),this);
  aSwitchLinesUpAction=new SwitchAction("switchLinesUp",KeyStroke.getKeyStroke(KeyEvent.VK_UP,Event.SHIFT_MASK),this);
  JTable table=m_curGC.getTable();
  table.getInputMap(CPanel.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN,Event.SHIFT_MASK),"none");
  table.getInputMap(CPanel.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_UP,Event.SHIFT_MASK),"none");
  table.getInputMap(CPanel.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN,Event.SHIFT_MASK),"none");
  table.getInputMap(CPanel.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_UP,Event.SHIFT_MASK),"none");
  getInputMap(CPanel.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN,Event.SHIFT_MASK),aSwitchLinesDownAction.getName());
  getActionMap().put(aSwitchLinesDownAction.getName(),aSwitchLinesDownAction);
  getInputMap(CPanel.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_UP,Event.SHIFT_MASK),aSwitchLinesUpAction.getName());
  getActionMap().put(aSwitchLinesUpAction.getName(),aSwitchLinesUpAction);
}
 

Example 21

From project Custom-Salem, under directory /src/haven/.

Source file: ChatUI.java

  15 
vote

public boolean type(char key,KeyEvent ev){
  if (qline != null) {
    qline.key(ev);
    return (true);
  }
 else {
    return (super.type(key,ev));
  }
}
 

Example 22

From project dawn-common, under directory /org.dawb.hdf5/src/ncsa/hdf/view/.

Source file: DefaultTableView.java

  15 
vote

/** 
 * creates a popup menu for a right mouse click on a data object 
 */
private JPopupMenu createPopupMenu(){
  JPopupMenu menu=new JPopupMenu();
  JMenuItem item;
  item=new JMenuItem("Show As Table");
  item.setMnemonic(KeyEvent.VK_T);
  item.addActionListener(this);
  item.setActionCommand("Show data as table");
  menu.add(item);
  item=new JMenuItem("Show As Image");
  item.setMnemonic(KeyEvent.VK_I);
  item.addActionListener(this);
  item.setActionCommand("Show data as image");
  menu.add(item);
  return menu;
}
 

Example 23

From project dawn-isencia, under directory /com.isencia.passerelle.commons/src/main/java/com/isencia/util/swing/calendar/.

Source file: JDayChooser.java

  15 
vote

/** 
 * JDayChooser is the KeyListener for all day buttons. (Added by Thomas Schaefer)
 */
public void keyPressed(KeyEvent e){
  if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
    firePropertyChange("escape",1,0);
    return;
  }
  if (e.getKeyCode() == KeyEvent.VK_PAGE_UP) {
    firePropertyChange("monthPlus1",1,0);
    return;
  }
  if (e.getKeyCode() == KeyEvent.VK_PAGE_DOWN) {
    firePropertyChange("monthMinus1",1,0);
    return;
  }
  if (e.getKeyCode() == KeyEvent.VK_SPACE) {
    firePropertyChange("closeMe",1,0);
    return;
  }
  if (e.getKeyCode() == KeyEvent.VK_ENTER) {
    firePropertyChange("closeMe",1,0);
    return;
  }
  int offset=e.getKeyCode() == KeyEvent.VK_UP ? -7 : e.getKeyCode() == KeyEvent.VK_DOWN ? +7 : e.getKeyCode() == KeyEvent.VK_LEFT ? -1 : e.getKeyCode() == KeyEvent.VK_RIGHT ? +1 : 0;
  for (int i=getComponentCount() - 1; i >= 0; --i)   if (getComponent(i) == selectedDay) {
    i+=offset;
    if (i < firstDay && (offset == 1 || offset == -1)) {
      firePropertyChange("monthMinus1",1,0);
      setDay(getLastDayOfPreviousMonth());
    }
 else     if (i > lastDay && (offset == 1 || offset == -1)) {
      firePropertyChange("monthPlus1",1,0);
      setDay(1);
    }
 else     if (i >= firstDay && i <= lastDay) {
      if (!days[i].hasFocus())       days[i].requestFocus();
 else       actionPerformed(new ActionEvent(days[i],0,null));
    }
    break;
  }
}
 

Example 24

From project des, under directory /daemon/lib/apache-log4j-1.2.16/src/main/java/org/apache/log4j/lf5/viewer/.

Source file: LogFactor5InputDialog.java

  15 
vote

/** 
 * Configures an input dialog box. param jframe the frame where the dialog will be loaded from. param title the title of the dialog box. param label the label to be put in the dialog box. param size the size of the text field.
 */
public LogFactor5InputDialog(JFrame jframe,String title,String label,int size){
  super(jframe,title,true);
  JPanel bottom=new JPanel();
  bottom.setLayout(new FlowLayout());
  JPanel main=new JPanel();
  main.setLayout(new FlowLayout());
  main.add(new JLabel(label));
  _textField=new JTextField(size);
  main.add(_textField);
  addKeyListener(new KeyAdapter(){
    public void keyPressed(    KeyEvent e){
      if (e.getKeyCode() == KeyEvent.VK_ENTER) {
        hide();
      }
    }
  }
);
  JButton ok=new JButton("Ok");
  ok.addActionListener(new ActionListener(){
    public void actionPerformed(    ActionEvent e){
      hide();
    }
  }
);
  JButton cancel=new JButton("Cancel");
  cancel.addActionListener(new ActionListener(){
    public void actionPerformed(    ActionEvent e){
      hide();
      _textField.setText("");
    }
  }
);
  bottom.add(ok);
  bottom.add(cancel);
  getContentPane().add(main,BorderLayout.CENTER);
  getContentPane().add(bottom,BorderLayout.SOUTH);
  pack();
  centerWindow(this);
  show();
}
 

Example 25

From project drugis-common, under directory /common-gui/src/main/java/org/drugis/common/gui/table/.

Source file: TableCopyHandler.java

  15 
vote

@SuppressWarnings("serial") public static void registerCopyAction(final JTable jtable){
  KeyStroke copy=KeyStroke.getKeyStroke(KeyEvent.VK_C,Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
  Action action=new AbstractAction("copy"){
    public void actionPerformed(    ActionEvent event){
      TableCopyHandler handler=new TableCopyHandler(jtable);
      Toolkit.getDefaultToolkit().getSystemClipboard().setContents(handler,handler);
    }
  }
;
  jtable.registerKeyboardAction(action,copy,JComponent.WHEN_FOCUSED);
}
 

Example 26

From project enclojure, under directory /netbeans/plugins/org-enclojure-plugin/src/main/java/org/enclojure/ide/nb/editor/completion/.

Source file: ClojureCodeCompletion_Provider.java

  15 
vote

public void keyPressed(KeyEvent e){
  int id=e.getID();
  if (id == KeyEvent.KEY_PRESSED) {
    int keyCode=e.getKeyCode();
    if ((keyCode == 44) && e.isControlDown())     if (autoCompletion)     autoCompletion=false;
 else     autoCompletion=true;
    if ((keyCode == 46) && e.isControlDown()) {
      Scenario1List.clear();
      Scenario2List.clear();
      Scenario3List.clear();
      Scenario4List.clear();
      Scenario1ListExtLib.clear();
      Scenario2ListExtLib.clear();
      Scenario4ListExtLib.clear();
    }
  }
}
 

Example 27

From project encog-java-workbench, under directory /src/main/java/org/encog/workbench/frames/document/tree/.

Source file: ProjectTree.java

  15 
vote

public void keyTyped(KeyEvent e){
  if (EncogWorkBench.getInstance().getMainWindow().getTabManager().notWithModalTabOpen())   return;
  if (e.getKeyChar() == KeyEvent.VK_DELETE) {
    EncogWorkBench.getInstance().getMainWindow().getOperations().performDelete();
  }
}
 

Example 28

From project Euclidean-Pattern-Generator, under directory /src/com/hisschemoller/sequencer/view/components/.

Source file: MenuBar.java

  15 
vote

public MenuBar(ActionListener actionListener){
  int shortcut=Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
  _fileMenu=new JMenu("File");
  add(_fileMenu);
  JMenuItem menuItem=new JMenuItem("New Project");
  menuItem.addActionListener(actionListener);
  menuItem.setActionCommand(NEW);
  menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,shortcut));
  _fileMenu.add(menuItem);
  menuItem=new JMenuItem("Open Project...");
  menuItem.addActionListener(actionListener);
  menuItem.setActionCommand(OPEN);
  menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,shortcut));
  _fileMenu.add(menuItem);
  menuItem=new JMenuItem("Save Project");
  menuItem.addActionListener(actionListener);
  menuItem.setActionCommand(SAVE);
  menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,shortcut));
  _fileMenu.add(menuItem);
  menuItem=new JMenuItem("Save Project As...");
  menuItem.addActionListener(actionListener);
  menuItem.setActionCommand(SAVE_AS);
  menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,shortcut | InputEvent.SHIFT_DOWN_MASK));
  _fileMenu.add(menuItem);
  _helpMenu=new JMenu("Help");
  add(_helpMenu);
  menuItem=new JMenuItem("Help Contents");
  menuItem.addActionListener(actionListener);
  menuItem.setActionCommand(HELP);
  _helpMenu.add(menuItem);
}
 

Example 29

From project extension_libero_manufacturing, under directory /extension/eevolution/libero/src/main/java/org/eevolution/form/.

Source file: CAbstractBOMTree.java

  15 
vote

public void keyReleased(KeyEvent e){
  if (e.getKeyCode() == 38 || e.getKeyCode() == 40) {
    TreePath path=model.getTree().getSelectionModel().getSelectionPath();
    String text=model.getBOMMessenger().getToolTipText(path);
    if (text != null) {
      nodeDescription.setText(text);
    }
  }
}
 

Example 30

From project flyingsaucer, under directory /flying-saucer-core/src/main/java/org/xhtmlrenderer/simple/.

Source file: FSScrollPane.java

  15 
vote

/** 
 * Assigns the default keyboard bindings on the view for document navigation. 
 */
private void setDefaultInputMap(JComponent view){
  view.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN,0),PAGE_DOWN);
  view.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP,0),PAGE_UP);
  view.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN,0),LINE_DOWN);
  view.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_UP,0),LINE_UP);
  view.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_END,KeyEvent.CTRL_MASK),PAGE_END);
  view.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_END,0),PAGE_END);
  view.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_HOME,KeyEvent.CTRL_MASK),PAGE_START);
  view.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_HOME,0),PAGE_START);
}
 

Example 31

From project formic, under directory /src/java/org/formic/util/event/gui/.

Source file: ButtonKeyListener.java

  15 
vote

/** 
 * {@inheritDoc}
 * @see KeyListener#keyPressed(KeyEvent)
 */
public void keyPressed(KeyEvent e){
  if (e.getKeyCode() == KeyEvent.VK_ENTER) {
    ((JButton)e.getSource()).doClick();
    e.consume();
  }
}
 

Example 32

From project gitblit, under directory /src/com/gitblit/client/.

Source file: EditRegistrationDialog.java

  15 
vote

@Override protected JRootPane createRootPane(){
  KeyStroke stroke=KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE,0);
  JRootPane rootPane=new JRootPane();
  rootPane.registerKeyboardAction(new ActionListener(){
    public void actionPerformed(    ActionEvent actionEvent){
      setVisible(false);
    }
  }
,stroke,JComponent.WHEN_IN_FOCUSED_WINDOW);
  return rootPane;
}
 

Example 33

From project Gmote, under directory /gmoteserver/src/org/gmote/server/media/basic/.

Source file: CommonOperations.java

  15 
vote

public static void sendCloseCommand() throws AWTException {
  Robot robot=new Robot();
  if (PlatformUtil.isMac()) {
    robot.keyPress(KeyEvent.VK_META);
    robot.keyPress(KeyEvent.VK_W);
    robot.keyRelease(KeyEvent.VK_W);
    robot.keyRelease(KeyEvent.VK_META);
  }
 else {
    robot.keyPress(KeyEvent.VK_ALT);
    robot.keyPress(KeyEvent.VK_F4);
    robot.keyRelease(KeyEvent.VK_F4);
    robot.keyRelease(KeyEvent.VK_ALT);
  }
}
 

Example 34

From project google-api-translate-java, under directory /src/main/java/com/google/api/translate/.

Source file: TranslatorFrame.java

  15 
vote

private void fromTextAreaKeyPressed(java.awt.event.KeyEvent evt){
  if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
    translate();
    evt.consume();
  }
}
 

Example 35

From project GraduationProject, under directory /tesseract-android-tools/external/tesseract-3.00/java/com/google/scrollview/events/.

Source file: SVEventHandler.java

  15 
vote

/** 
 * A key was pressed - create an SVET_INPUT event. NOTE: Might be useful to specify hotkeys. Implementation note: The keyListener provided by Piccolo seems to be broken, so we use the AWT listener directly. There are never any keyTyped events received either so we are stuck with physical keys, which is very ugly.
 */
public void keyPressed(KeyEvent e){
  char keyCh=e.getKeyChar();
  if (keyCh == '\r' || keyCh == '\n' || keyCh == '\0' || keyCh == '?') {
    processEvent(new SVEvent(SVEventType.SVET_INPUT,svWindow,lastXMove,lastYMove,0,0,keyStr));
    keyStr="!";
  }
 else {
    processEvent(new SVEvent(SVEventType.SVET_INPUT,svWindow,lastXMove,lastYMove,0,0,String.valueOf(keyCh)));
    keyStr+=keyCh;
  }
}
 

Example 36

From project GraphLab, under directory /src/graphlab/plugins/main/select/.

Source file: DeleteSelected.java

  15 
vote

/** 
 * constructor
 * @param bb the blackboard of the action
 */
public DeleteSelected(BlackBoard bb){
  this.blackboard=bb;
  KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventPostProcessor(new KeyEventPostProcessor(){
    public boolean postProcessKeyEvent(    KeyEvent e){
      AbstractGraphRenderer gv=blackboard.getData(AbstractGraphRenderer.EVENT_KEY);
      Component focusOwner=KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
      if (gv == focusOwner) {
        if (e.getKeyCode() == KeyEvent.VK_DELETE) {
          action(new GraphData(blackboard));
          return true;
        }
      }
      return false;
    }
  }
);
}
 

Example 37

From project grid-goggles, under directory /Dependent Libraries/controlP5/src/controlP5/.

Source file: ListBox.java

  15 
vote

/** 
 * Adding key support. up and down arrows can be used to scroll listbox or dropdownList,up and down, use shift+up/down for faster scrolling, use alt+up/down to jump to the top or bottom.
 * @exclude {@inheritDoc}
 */
@ControlP5.Invisible public void keyEvent(final KeyEvent theEvent){
  super.keyEvent(theEvent);
  float x=getAbsolutePosition().x;
  float y=getAbsolutePosition().y;
  boolean b=(getWindow().mouseX > x && getWindow().mouseX < (x + _myWidth) && getWindow().mouseY > (y - getBarHeight()) && getWindow().mouseY < y + _myOriginalBackgroundHeight);
  if (b && isOpen()) {
    float step=(1.0f / (float)items.size());
    if (cp5.keyHandler.isShiftDown) {
      step*=10;
    }
 else     if (cp5.keyHandler.isAltDown) {
      step=1;
    }
    if (theEvent.getID() == KeyEvent.KEY_PRESSED) {
switch (theEvent.getKeyCode()) {
case (KeyEvent.VK_UP):
        _myScrollbar.setValue(PApplet.constrain(_myScrollbar.getValue() + step,0,1));
      break;
case (KeyEvent.VK_DOWN):
    _myScrollbar.setValue(PApplet.constrain(_myScrollbar.getValue() - step,0,1));
  break;
}
}
}
}
 

Example 38

From project gridland, under directory /src/org/grid/agent/sample/.

Source file: HumanAgent.java

  15 
vote

@Override public boolean dispatchKeyEvent(KeyEvent e){
  if (!isAlive())   return false;
switch (e.getKeyCode()) {
case KeyEvent.VK_UP:
    move(Direction.UP);
  break;
case KeyEvent.VK_LEFT:
move(Direction.LEFT);
break;
case KeyEvent.VK_RIGHT:
move(Direction.RIGHT);
break;
case KeyEvent.VK_DOWN:
move(Direction.DOWN);
break;
}
return false;
}
 

Example 39

From project gs-tool, under directory /src/org/graphstream/tool/gui/.

Source file: ReaderFromWindow.java

  15 
vote

public ReaderFromWindow(int width,int height){
  frame=new JDialog();
  buffer=new StringBuffer();
  text=new JTextArea(3,30);
  text.setFont(Resources.getMonospaceFont(14.0f));
  text.getKeymap().addActionForKeyStroke(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,KeyEvent.SHIFT_MASK),new FlushAction());
  pane=new JTextPane();
  pane.setSize(width,height);
  pane.setEditable(false);
  pane.setBackground(Resources.getColor(Resources.ColorType.BACKGROUND_RIGHT));
  pane.setFont(Resources.getMonospaceFont(14.0f));
  JScrollPane scroller1=new JScrollPane(pane);
  JScrollPane scroller2=new JScrollPane(text);
  JSplitPane split=new JSplitPane(JSplitPane.VERTICAL_SPLIT,scroller1,scroller2);
  scroller2.setPreferredSize(new Dimension(text.getPreferredSize().width,text.getPreferredSize().height + 5));
  scroller1.setPreferredSize(new Dimension(width,height - scroller2.getPreferredSize().height));
  split.resetToPreferredSizes();
  frame.add(split);
  frame.pack();
  frame.addWindowListener(new CloseHandler());
  frame.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
}
 

Example 40

From project Holo-Edit, under directory /holoedit/functions/.

Source file: AlgorithmDialog.java

  15 
vote

public void keyReleased(KeyEvent ke){
switch (ke.getKeyCode()) {
case 27:
    CancelMouseClicked();
  break;
default :
break;
}
}
 

Example 41

From project Hotel-Management_MINF10-HCM, under directory /HotelManagement/src/main/java/core/datechooser/.

Source file: JDayChooser.java

  15 
vote

/** 
 * JDayChooser is the KeyListener for all day buttons. (Added by Thomas Schaefer and modified by Austin Moore)
 * @param e the KeyEvent
 */
public void keyPressed(KeyEvent e){
  int offset=(e.getKeyCode() == KeyEvent.VK_UP) ? (-7) : ((e.getKeyCode() == KeyEvent.VK_DOWN) ? (+7) : ((e.getKeyCode() == KeyEvent.VK_LEFT) ? (-1) : ((e.getKeyCode() == KeyEvent.VK_RIGHT) ? (+1) : 0)));
  int newDay=getDay() + offset;
  if ((newDay >= 1) && (newDay <= calendar.getMaximum(Calendar.DAY_OF_MONTH))) {
    setDay(newDay);
  }
}