Exemplo n.º 1
0
  /** "Return" invokes smart scroll, which closes up current section, and opens next. */
  public boolean eventAfter(AWTEvent e, Point scrn, Node obsn) {
    int eid = e.getID();
    // System.out.println("Outliner eventBefore "+eid+", outActive_="+outActive_);
    if (outActive_ != null
        && outActive_.isSet()
        && outActive_.isOpen() /*always true?*/ /* && outSects_.indexOf(outActive_)==-1*/
        && /*active_ &&*/ eid == KeyEvent.KEY_PRESSED
        && ((KeyEvent) e).getKeyChar() == ' ' // ).getKeyCode()==KeyEvent.VK_ENTER
    ) {
      Browser br = getBrowser();

      // find next
      OutlineSpan next = nextSection(outActive_.getStart().leaf);
      Node outn = outActive_.getStart().leaf;
      IScrollPane isp = outn.getIScrollPane();
      VScrollbar vsb = isp.getVsb();
      int y = vsb.getValue(), h = isp.bbox.height;

      if (next != null) {
        Leaf l = (Leaf) next.getStart().leaf;
        Point rel = l.getRelLocation(isp);

        // if next on screen open next, closing up previous of <= level
        // System.out.println(y+" .. "+l.getNextLeaf()+"/"+rel.y+" .. "+(y+h));
        if (y < rel.y && rel.y < y + h) {
          // close up current and previous while <= level

          int level = Integers.parseInt(next.getAttr(OutlineSpan.ATTR_LEVEL), 1);

          for (OutlineSpan prev = outActive_;
              prev != null;
              prev = prevSection(prev.getStart().leaf)) {
            br.eventq(OutlineSpan.MSG_CLOSE, prev);
            if (Integers.parseInt(prev.getAttr(OutlineSpan.ATTR_LEVEL), Integer.MIN_VALUE) <= level)
              break; // stop after first at same level as next/new current
          }

          outActive_ = next;
          br.eventq(OutlineSpan.MSG_OPEN, outActive_); // includes l.scrollTo(0,0, true);
          // System.out.println("open "+outActive_);
        } // else fall through to scroll
        return true;

      } else if (y + h >= vsb.getMax()) { // at end, just close up
        // System.out.println("couldn't find next OutlineSpan"); -- at end
        br.eventq(OutlineSpan.MSG_CLOSE, outActive_);
        outActive_ = null;
      }

      // close current and open next
      // br.setGrab(this);	// get key release
      // return true;
    }

    return false;
  }