Code example for MouseEvent

Methods: getIDisConsumedisShiftDowngetPoint

0
    return new MouseInputListener() {
      public void mouseClicked(MouseEvent e) {}
      public void mouseEntered(MouseEvent e) {}
      public void mouseExited(MouseEvent e) {}
      public void mousePressed(MouseEvent e) {
        if (e.isConsumed()) {
          selectedOnPress = false;
          return; 
        } 
        selectedOnPress = true;
        adjustFocusAndSelection(e);
      } 
 
      void adjustFocusAndSelection(MouseEvent e) {
        if (!SwingUtilities.isLeftMouseButton(e)) {
          return; 
        } 
 
        if (!list.isEnabled()) {
          return; 
        } 
 
        /* Request focus before updating the list selection.  This implies 
         * that the current focus owner will see a focusLost() event 
         * before the lists selection is updated IF requestFocus() is 
         * synchronous (it is on Windows).  See bug 4122345 
         */ 
        if (!list.hasFocus() && list.isRequestFocusEnabled()) {
          list.requestFocus();
        } 
 
        int row = locationToIndex(list, e.getPoint());
        if (row != -1) {
          myLastPressedRow = row;
          boolean adjusting = (e.getID() == MouseEvent.MOUSE_PRESSED) ? true : false;
          list.setValueIsAdjusting(adjusting);
          int anchorIndex = list.getAnchorSelectionIndex();
          if (e.isShiftDown() && (anchorIndex != -1)) {
            list.setSelectionInterval(anchorIndex, row);
          } else { 
            toggleSelection(row);
          } 
        }