Exemple #1
0
    public void onKeyDown(KeyDownEvent event) {
      if (event.getSource() == input_) return;

      // Filter out some keystrokes you might reasonably expect to keep
      // focus inside the output pane
      switch (event.getNativeKeyCode()) {
        case KeyCodes.KEY_PAGEDOWN:
        case KeyCodes.KEY_PAGEUP:
        case KeyCodes.KEY_HOME:
        case KeyCodes.KEY_END:
        case KeyCodes.KEY_CTRL:
        case KeyCodes.KEY_ALT:
        case KeyCodes.KEY_SHIFT:
        case 224: // META (Command) on Firefox/Mac
          return;
        case 91:
        case 93: // Left/Right META (Command), but also [ and ], on Safari
          if (event.isMetaKeyDown()) return;
          break;
        case 'C':
          if (event.isControlKeyDown() || event.isMetaKeyDown()) return;
          break;
      }
      input_.setFocus(true);
      delegateEvent(input_.asWidget(), event);
    }
 @Override
 public void onKeyDown(KeyDownEvent event) {
   int key = event.getNativeKeyCode();
   if (event.isControlKeyDown()) {
     if (key == KEY_PLUS || key == KEY_MINUS) {
       app.getToolbar().zoomChangeClicked(key == KEY_PLUS ? 1 : -1);
       event.preventDefault();
     }
   } else if (!event.isShiftKeyDown()) {
     boolean handled = true;
     switch (key) {
       case KeyCodes.KEY_UP:
         if (!tryPan(0, -PAN_STEP)) changePage(page - 1, 0, 1);
         break;
       case KeyCodes.KEY_DOWN:
         if (!tryPan(0, PAN_STEP)) changePage(page + 1, 0, -1);
         break;
       case KeyCodes.KEY_LEFT:
         if (!tryPan(-PAN_STEP, 0)) changePage(page - 1, 1, 0);
         break;
       case KeyCodes.KEY_RIGHT:
         if (!tryPan(PAN_STEP, 0)) changePage(page + 1, -1, 0);
         break;
       case KeyCodes.KEY_PAGEUP:
         if (!tryPan(0, -canvas.getCoordinateSpaceHeight() + PAN_STEP))
           changePage(page - 1, 0, 1);
         break;
       case KeyCodes.KEY_PAGEDOWN:
       case KeyCodes.KEY_SPACE:
         if (!tryPan(0, canvas.getCoordinateSpaceHeight() - PAN_STEP))
           changePage(page + 1, 0, -1);
         break;
       case KeyCodes.KEY_HOME:
         changePage(0, -1, -1);
         break;
       case KeyCodes.KEY_END:
         changePage(app.getPageCache().getPageCount() - 1, 1, 1);
         break;
       default:
         handled = false;
     }
     if (handled) event.preventDefault();
   }
 }
  /* (non-Javadoc)
   * @see com.google.gwt.event.dom.client.KeyDownHandler#onKeyDown(com.google.gwt.event.dom.client.KeyDownEvent)
   */
  @Override
  public void onKeyDown(KeyDownEvent event) {
    //		System.out.println(event.getNativeKeyCode());
    int keyCode = event.getNativeKeyCode();
    if (selectedNode != null) {
      short nodeType = selectedNode.getNodeType();
      if (event.isControlKeyDown()) {
        if (keyCode == ClauseConstants.COPY_C) { // COPY
          if ((nodeType != CellTreeNode.MASTER_ROOT_NODE) && (nodeType != CellTreeNode.ROOT_NODE)) {
            popupPanel.hide();
            copy();
          }

        } else if (keyCode == ClauseConstants.PASTE_V) { // PASTE
          boolean canPaste = false;
          popupPanel.hide();
          if (copiedNode != null) {
            switch (selectedNode.getNodeType()) {
              case CellTreeNode.ROOT_NODE:
                if (selectedNode.equals(copiedNode.getParent())) {
                  clauseWorkspaceContextMenu.pasteRootNodeTypeItem();
                  isDirty = true;
                }
                break;
              case CellTreeNode.LOGICAL_OP_NODE:
              case CellTreeNode.FUNCTIONS_NODE:
                if (copiedNode.getNodeType() != CellTreeNode.CLAUSE_NODE) {
                  canPaste = true;
                }
                break;
              case CellTreeNode.TIMING_NODE:
                if ((copiedNode.getNodeType() != CellTreeNode.CLAUSE_NODE)
                    && ((selectedNode.getChilds() == null)
                        || (selectedNode.getChilds().size() < 2))) {
                  canPaste = true;
                }
                break;
              default:
                break;
            }
            if (canPaste) {
              paste();
              isDirty = true;
            }
          }

        } else if (keyCode == ClauseConstants.CUT_X) { // CUT
          popupPanel.hide();
          if ((selectedNode.getNodeType() != CellTreeNode.MASTER_ROOT_NODE)
              && (selectedNode.getNodeType() != CellTreeNode.CLAUSE_NODE)
              && (selectedNode.getNodeType() != CellTreeNode.ROOT_NODE)
              && (selectedNode.getParent().getNodeType() != CellTreeNode.CLAUSE_NODE)) {
            copy();
            removeNode();
            isDirty = true;
          }
        }
      } else if (keyCode == ClauseConstants.DELETE_DELETE) { // DELETE
        popupPanel.hide();
        if (((selectedNode.getNodeType() != CellTreeNode.MASTER_ROOT_NODE)
                && (selectedNode.getNodeType() != CellTreeNode.ROOT_NODE)
                && (selectedNode.getParent().getNodeType() != CellTreeNode.CLAUSE_NODE)
                && (selectedNode.getNodeType() != CellTreeNode.CLAUSE_NODE))
            || ((selectedNode.getNodeType() == CellTreeNode.CLAUSE_NODE)
                && (selectedNode.getParent().getChilds().size() > 1))) {
          removeNode();
          isDirty = true;
        }
      }
    }
    if ((event.isShiftKeyDown()
        && ((keyCode == ClauseConstants.PLUS_FF) || (keyCode == ClauseConstants.PLUS_IE)))) {
      // EXPAND/COLLAPSE (+(Shift +) Expand| - Collapse)
      popupPanel.hide();
      openAllNodes(cellTree.getRootTreeNode());
    } else if ((event.isShiftKeyDown()
        && ((keyCode == ClauseConstants.MINUS_FF) || (keyCode == ClauseConstants.MINUS_IE)))) {
      popupPanel.hide();
      closeNodes(cellTree.getRootTreeNode());
    }
    /*if(event.isControlKeyDown() && event.isAltKeyDown() && keyCode == 83){
    	saveBtn.getElement().focus();
    	saveBtn.click();
    }*/
  }