1 Reply Latest reply: Jun 22, 2010 7:04 AM by 843799 RSS

    recieving press MouseEvents immediately after release MouseEvents

    843799
      When I release the mouse with this code, it receives a MouseEvent that says it's released, and then immediately afterward one that says it's been pressed again.

      This is the code that processes the press events... (I am fully aware of how awful it is):
          public void processStimulus(Enumeration criteria) {
      ...
                  if( !editBehavior.existsSelectedLocatable()){
                      while(criteria.hasMoreElements()){
                          WakeupCriterion i= (WakeupCriterion) criteria.nextElement();
                          if(i instanceof WakeupOnAWTEvent){
                              AWTEvent[] events = ((WakeupOnAWTEvent)i).getAWTEvent();
                              for (AWTEvent j: events){
                                  if(j instanceof MouseEvent){
                                      MouseEvent mevt = (MouseEvent)j;
                                      if (mevt.getButton() == MouseEvent.BUTTON1 &&
                                            mevt.getID() == MouseEvent.MOUSE_PRESSED &&
                                            (mevt.getModifiers() & InputEvent.BUTTON1_MASK)
                                            == InputEvent.BUTTON1_MASK){
                                          PickResult result = pickPelvic();
                                          if (result != null){
                                              System.out.print("mouse event "+  mevt);
                                              Node shape = result.getNode(PickResult.SHAPE3D);
                                              Instrument instrument = (Instrument) shape.getUserData();
                                              instrument.selectLeftClick();
                                              mevt.consume();
                                          }
                                      }
                                  }
                              }
                          }
                      }
                  }
              }
              wakeupOn(condition);
          }
      and this is the code that processes release events:
          public void processStimulus(Enumeration criteria) {
              if (manager.isEditMode()){
                  while(criteria.hasMoreElements()){
                      WakeupCriterion i= (WakeupCriterion) criteria.nextElement();
                      if(i instanceof WakeupOnAWTEvent){
                          AWTEvent[] events = ((WakeupOnAWTEvent)i).getAWTEvent();
                          for (AWTEvent j: events){
                              if (j instanceof KeyEvent){
      
      ...
                              }else if(j instanceof MouseEvent){
                                  MouseEvent mevt = (MouseEvent)j;
                                  if (mevt.getButton() == MouseEvent.BUTTON1 && 
                                          mevt.getID() == MouseEvent.MOUSE_RELEASED 
                                          && instrument != null){
                                      System.out.print("mouse event " + mevt);
                                      releaseInstrument();
                                      ((MouseEvent)j).consume();
                                  }
                              }
                          }
                      }
                  }
                  if(instrument instanceof Locatable){
                      computePosition();
                  }
              }
              wakeupOn(condition); 
          }
      I'm not sure what I'm doing to cause the spurious press events.