Package ket

Examples of ket.Selection


    // TODO: Re-join wrapped lines, 'text... \'?
    if (lines.length==1) {
      // Single line.
      Argument arg = ArgumentParser.parseArgument(string, knownArguments, clipboard, mathCollection);
      if (arg!=null) {
        Selection selection = mathCollection.getSelection();
        Equation appendedEquation = new Equation(arg);
        selection.appendEquation(appendedEquation);
      }
    } else {
      // Multiple lines.
      for (String next : lines) {
        Equation e = mathCollection.processLine(next);
        if (e!=null) {
          Selection selection = mathCollection.getSelection();
          Equation appendedEquation = new Equation(e.getRoot());
          selection.appendEquation(appendedEquation);
        }
      }
    }
    ketPanel.updateAndRepaint();
    return true;
View Full Code Here


  }

  @Override
  protected void insert(Purpose purpose) {
    Document d = getDocument();
    Selection s = d.getSelection();
    Argument current = s.getCurrent();
    if (current.isBranch() && updatePurpose) {
      current.asBranch().setFunction((Function) purpose);
    } else {
      s.addIntermediaryParent((Function) purpose);
    }
  }
View Full Code Here

  // Replace current?
  private void moveRelative(KeyPress keyPress) {
    char character = keyPress.getChar();
    Ket.out.println(" --- move relative ("+character+") --- ");
    Argument current = getSelection().getCurrent();
    Selection s = getSelection();
    Cursor c = s.getCursor();
    Argument replacement = document.parseArgument(getLine());
    boolean ok;
    switch (character) {
      case 'i': // TODO: Merge with appendNewSibling().
        ok = current.isBranch() || s.variableTokenToBranch(knownArguments);
        if (!ok) return;
        if (replacement!=null) {
          s.replace(replacement);
        }
        if (relative==RELATIVE_EDIT) {
          s.prependNewChild();
        } else {
          c.selectInOrOutLeft();
          setMessage(current.toString());
        }
        break;
      case 'o': // TODO: Merge with prependNewSibling().
        ok = current.isBranch() || s.variableTokenToBranch(knownArguments);
        if (!ok) return;
        if (replacement!=null) {
          s.replace(replacement);
        }
        if (relative==RELATIVE_EDIT) {
          s.appendNewChild();
        } else {
          c.selectInOrOutRight();
          setMessage(current.toString());
        }
        break;
      case 'h':
        if (replacement!=null) {
          s.replace(replacement);
        }
        if (relative==RELATIVE_EDIT) {
          s.prependNewSibling();
        } else {
          c.selectLeft();
          setMessage(current.toString());
        }
        break;
      case 'l':
        if (replacement!=null) {
          s.replace(replacement);
        }
        if (relative==RELATIVE_EDIT) {
          s.appendNewSibling();
        } else {
          c.selectRight();
          setMessage(current.toString());
        }
        break;
      case 'e':
      case 'j':
      case 'k':
        boolean prepend = (character=='k');
        insertEquation(prepend);
        break;
      case ' ':
        if (replacement!=null) {
          s.replace(replacement);
        }
        if (relative==RELATIVE_EDIT) {
          document.getModes().setDocumentState(DocumentState.APPEND_PURPOSE);
          s.addNewIntermediaryParent();
        } else {
          document.getModes().setDocumentState(DocumentState.APPEND_PURPOSE);
          c.selectParent();
          setMessage(getSelection().getCurrent().getPurpose().getName());
        }
        softReset();
        // Note: Don't clear the message!
        return;
      default:
        // TODO: If you are only moving then approach this command as 'f*' or 'F+'.
        Function knownFunction =  knownArguments.getFunctionByChar(character);
        if (replacement!=null) {
          s.replace(replacement);
        }
        s.addIntermediaryParent(knownFunction);
        s.appendNewChild();
    }
    clear();
    softReset();
  }
View Full Code Here

  public void updateSelection() {
    mathCollection.updateUndoStack();
    Argument current = getSelection().getCurrent();
    EquationList el = current.getEquationList();
    Selection s = getSelection();
    Argument replacement = document.parseArgument(line.getLine());
    if (replacement!=null) {
      s.replace(replacement);
    }
  }
View Full Code Here

    if (replacement!=null) {
      s.replace(replacement);
    }
    */
    updateSelection();
    Selection s = getSelection();
    if (prepend) {
      s.prependEquation(new Equation());
    } else {
      s.appendEquation(new Equation());
    }
  }
View Full Code Here

      s.appendEquation(new Equation());
    }
  }

  public void toggleTextEquation() {
    Selection s = getSelection();
    Chord chord = document.getKeyboardEventHandler().getChord();
    String line = getLine();
    boolean nonblank = ! ("".equals(line));
    if (document.getModes().getDocumentState()==DocumentState.UPDATE_TEXT) { //! UPDATE_SUBSTITUTE UPDATE_TEXT
      // BROKEN
      document.getModes().setDocumentState(DocumentState.UPDATE_REPLACE);
      Argument replacement = nonblank ? document.parseArgument(line) : null;
      if (replacement!=null) {
        s.replace(replacement);
        setMessage(line);
      }
    } else {
      // WORKS!
      document.getModes().setDocumentState(DocumentState.UPDATE_TEXT);
      if (nonblank) {
        s.replace(new Token(new Text(line)));
        setMessage(line);
      }
    }
  }
View Full Code Here

    document.getModes().getAddMode().appendEquation(chord);
  }

  public void appendNewSibling() {
    Argument current = getSelection().getCurrent();
    Selection s = getSelection();
    Cursor c = s.getCursor();
    Argument replacement = document.parseArgument(getLine());
    boolean ok = current.isBranch() || s.variableTokenToBranch(knownArguments);
    if (!ok) return;
    // TODO: What about current.isRoot()?
    if (replacement!=null) {
      s.replace(replacement);
    }
    s.appendNewSibling();
    clear();
  }
View Full Code Here

    clear();
  }

  public void prependNewSibling() {
    Argument current = getSelection().getCurrent();
    Selection s = getSelection();
    Cursor c = s.getCursor();
    Argument replacement = document.parseArgument(getLine());
    boolean ok = current.isBranch() || s.variableTokenToBranch(knownArguments);
    if (!ok) return;
    // TODO: What about current.isRoot()?
    if (replacement!=null) {
      s.replace(replacement);
    }
    s.prependNewSibling();
    clear();
  }
View Full Code Here

    clear();
  }

  public void appendNewChild() {
    Argument current = getSelection().getCurrent();
    Selection s = getSelection();
    Cursor c = s.getCursor();
    Argument replacement = document.parseArgument(getLine());
    boolean ok = current.isBranch() || s.variableTokenToBranch(knownArguments);
    if (!ok) return;
    if (replacement!=null) {
      s.replace(replacement);
    }
    s.appendNewChild();
    clear();
  }
View Full Code Here

    clear();
  }

  public void prependNewChild() {
    Argument current = getSelection().getCurrent();
    Selection s = getSelection();
    Cursor c = s.getCursor();
    Argument replacement = document.parseArgument(getLine());
    boolean ok = current.isBranch() || s.variableTokenToBranch(knownArguments);
    if (!ok) return;
    if (replacement!=null) {
      s.replace(replacement);
    }
    s.prependNewChild();
    clear();
  }
View Full Code Here

TOP

Related Classes of ket.Selection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.