示例#1
0
 private FigureNavigator navigator() {
   Control canvas = getCanvas();
   if (canvas instanceof FigureCanvas) {
     return FigureNavigator.getNavigatorForRoot(((FigureCanvas) canvas).getContents());
   } else {
     throw new RuntimeException("Bad Canvas");
   }
 }
示例#2
0
 public void keyPressed(KeyEvent event) {
   if (context.getFocused() != this) return;
   applyShortcut(event.keyCode, event.stateMask);
   if (event.character == '\r' && event.stateMask == 0) {
     replaceContent();
   } else if (event.stateMask == (SWT.ALT | SWT.SHIFT)) {
     FigureNavigator nav = navigator();
     try {
       VisualTerm other = null;
       switch (event.keyCode) {
         case SWT.ARROW_UP:
           other =
               (VisualTerm)
                   nav.getLastSmallestDecscendant(
                       nav.getFirstDescendantOfPrevSibling(
                           this, VerticalFlow.class, VisualTerm.class),
                       VisualTerm.class);
           break;
         case SWT.ARROW_DOWN:
           other =
               (VisualTerm)
                   nav.getFirstSmallestDecscendant(
                       nav.getFirstDescendantOfNextSibling(
                           this, VerticalFlow.class, VisualTerm.class),
                       VisualTerm.class);
           break;
         case SWT.ARROW_LEFT:
           other =
               (VisualTerm)
                   nav.getLastSmallestDecscendant(
                       nav.getFirstDescendantOfPrevSibling(
                           this, HorizontalFlow.class, VisualTerm.class),
                       VisualTerm.class);
           break;
         case SWT.ARROW_RIGHT:
           other =
               (VisualTerm)
                   nav.getFirstSmallestDecscendant(
                       nav.getFirstDescendantOfNextSibling(
                           this, HorizontalFlow.class, VisualTerm.class),
                       VisualTerm.class);
           break;
         case SWT.PAGE_UP:
           other = (VisualTerm) nav.getAncestor(getParent(), VisualTerm.class);
           break;
         case SWT.PAGE_DOWN:
         case SWT.HOME:
           other = (VisualTerm) nav.getFirstDescendant(this, VisualTerm.class, false);
           break;
         case SWT.END:
           other = (VisualTerm) nav.getLastDescendant(this, VisualTerm.class);
           break;
       }
       if (other != null) other.focusGained(null);
     } catch (FigureNotFoundException e) {
       // No navigation...
     }
   }
 }