Ejemplo n.º 1
1
  public String getTextForGesture(long parId, Point topLeft, Point bottomRight) {

    try {
      Paragraph p = lockManager.getParFromId(parId);

      int parY = documentPanel.textPane.modelToView(p.getOffset()).y;

      topLeft.y = topLeft.y + parY;
      bottomRight.y = bottomRight.y + parY;

      int startOffset = documentPanel.textPane.viewToModel(topLeft);
      int endOffset = documentPanel.textPane.viewToModel(bottomRight);

      while (startOffset > 0
          && Character.isLetterOrDigit((document.getText(startOffset - 1, 1).charAt(0))))
        startOffset--;

      while (endOffset < document.getLength()
          && Character.isLetterOrDigit((document.getText(endOffset, 1).charAt(0)))) endOffset++;

      String text = document.getText(startOffset, endOffset - startOffset);
      return text;
    } catch (Exception e) {
      System.out.println("EditorClient: addGestureAction. error identifying text");
      e.printStackTrace();
      return "";
    }

    // return "PLACEBO";
  }
Ejemplo n.º 2
0
  public void sendHighlights() {

    // send highlights to everybody
    try {
      Iterator i = highlights.getHighlights().iterator();
      while (i.hasNext()) {
        Highlights.Highlight h = (Highlights.Highlight) i.next();
        Paragraph sPar = lockManager.getParFromOffset(h.getStart());
        Paragraph ePar = lockManager.getParFromOffset(h.getEnd());

        if (EditorServer_Debug) {
          System.out.println("StartPar: " + sPar.toString());
          System.out.println("EndPar: " + ePar.toString());
        }

        Message.HighlightAddMsg msg =
            new Message.HighlightAddMsg(
                -1,
                h.getId(),
                h.getType().getId(),
                sPar.getID(),
                ePar.getID(),
                h.getStart() - sPar.getOffset(),
                h.getEnd() - ePar.getOffset());
        textChannel.sendToOthers(client, new Data(msg));
      }
    } catch (Exception e) {
      System.err.println("EditorServer: sendHighlights: error sending msg");
      if (EditorServer_Debug) e.printStackTrace();
    }
  }
Ejemplo n.º 3
0
  public long getParIdForGesture(long startParId, int y) {
    Paragraph startPar = lockManager.getParFromId(startParId);
    int startParY = documentPanel.getYValueFromOffset(startPar.getOffset());

    int offset = documentPanel.getOffsetFromPoint(new Point(25, startParY + y));
    return lockManager.getParFromOffset(offset).getID();
  }
Ejemplo n.º 4
0
  public void textInserted(Message.TextPasteMsg m) {

    try {

      int SenderId = m.getClientId();
      int offset = m.getOffset();
      String textPasted = m.getText();

      if (EditorServer_Debug)
        System.err.println("EditorServer->textinserted : PASTED by : " + SenderId);

      Vector pars = null;
      try {
        pars = lockManager.textInserted(m.getPar(), offset, textPasted, SenderId);
        if (EditorServer_Debug)
          System.err.println("\n+=*%EditorServer--> textInserted recovered VECTOR...");
      } catch (Exception e) {
        System.err.println("\n+=*%EditorServer--> textInserted VECTOR error ");
      }

      textChannel.sendToOthers(client, new Data(m));

      EditorClient SenderClient = getEditorClient(SenderId);
      SenderClient.addTextPasteAction(System.currentTimeMillis(), pars, offset, textPasted);
      clientsPanel.updateActionTableFor(SenderClient);
      updateParagraphList();
    } catch (Exception e) {
      System.err.println("\nEditorServer--> textPasted: error sending msg");
      if (EditorServer_Debug) e.printStackTrace();
    }
  }
Ejemplo n.º 5
0
  public void textInserted(Message.TextInsertMsg m) {
    if (EditorServer_Debug) System.err.println("EditorServer-> textInserted.");

    try {
      int ClientId = m.getClientId();
      int offset = m.getOffset();
      String characterInserted = m.getText();

      if (EditorServer_Debug)
        System.out.println("EditorServer-> textInserted : *" + characterInserted + "*");

      Vector pars = lockManager.textInserted(m.getPar(), offset, characterInserted, ClientId);

      textChannel.sendToOthers(client, new Data(m));
      EditorClient c = getEditorClient(ClientId);

      // new condition inserted to avoid timestamp generation if the character
      // is a newline

      if (characterInserted.equals("\n")) {
        if (EditorServer_Debug)
          System.out.println("EditorServer-> textInserted : attempting to insert a newLine");
      }
      c.addTextInsertAction(System.currentTimeMillis(), pars, offset, characterInserted);
      clientsPanel.updateActionTableFor(c);
      updateParagraphList();

    } catch (Exception e) {
      System.err.println("EditorServer-> textInserted: error receiving-sending msg");
      if (EditorServer_Debug) e.printStackTrace();
    }
  }
Ejemplo n.º 6
0
 public void sendDocumentState(int clientId) {
   Message.DocumentStateMsg msg =
       new Message.DocumentStateMsg(clientId, lockManager.getDocumentAsXML());
   try {
     clientChannel.sendToOthers(client, new Data(msg));
   } catch (Exception e) {
     System.err.println("EditorServer: sendDocumentState: error sending msg");
     if (EditorServer_Debug) e.printStackTrace();
   }
 }
Ejemplo n.º 7
0
  public void lockReleased(Message.LockReleaseMsg m) {
    if (EditorServer_Debug) System.err.println("EditorServer: lockReleased.");

    lockManager.lockReleased(m.getStartPar(), m.getEndPar(), m.getClientId());
    try {
      textChannel.sendToOthers(client, new Data(m));
    } catch (Exception e) {
      System.err.println("EditorServer: lockReleased: error sending lock released");
      if (EditorServer_Debug) e.printStackTrace();
    }
  }
Ejemplo n.º 8
0
  public void textDeleted(Message.TextCutMsg m) {
    if (EditorServer_Debug) System.err.println("EditorServer ->textCut.");

    try {

      long StartPar = m.getStartPar();
      long EndPar = m.getEndPar();
      int StartOffset = m.getStartOffset();
      int EndOffset = m.getEndOffset();

      String text = lockManager.getText(StartPar, StartOffset, EndPar, EndOffset);
      Vector pars = lockManager.textDeleted(StartPar, StartOffset, EndPar, EndOffset);
      textChannel.sendToOthers(client, new Data(m));
      EditorClient c = getEditorClient(m.getClientId());
      c.addTextCutAction(System.currentTimeMillis(), pars, StartOffset, EndOffset, text);
      clientsPanel.updateActionTableFor(c);
      updateParagraphList();
    } catch (Exception e) {
      System.err.println("EditorServer---> textDeleted(cut): error sending msg");
      if (EditorServer_Debug) e.printStackTrace();
    }
  }
Ejemplo n.º 9
0
  public void lockRequested(Message.LockRequestMsg m) {
    if (EditorServer_Debug) System.err.println("EditorServer -> lockRequested.");

    /*
      java.util.Timer t = new java.util.Timer() ;
      t.schedule(new TimerTask() {
      public void run() {
      client.lockDenied(id) ;
      }
      }, 3000) ;
    */

    if (lockManager.lockRequested(m.getStartPar(), m.getEndPar(), m.getClientId())) {

      if (EditorServer_Debug) System.out.println("Lock Granted");

      Message.LockGrantMsg reply =
          new Message.LockGrantMsg(
              m.getClientId(), m.getStartPar(), m.getEndPar(), m.getIdNumber());
      try {
        textChannel.sendToOthers(client, new Data(reply));
      } catch (Exception e) {
        System.err.println("EditorServer: lockRequested: error sending lock granted");
        if (EditorServer_Debug) e.printStackTrace();
      }
    } else {
      if (EditorServer_Debug) System.out.println("Lock Denied");
      // send lock denied to sender

      Message.LockDenyMsg reply = new Message.LockDenyMsg(m.getClientId(), m.getIdNumber());
      try {
        textChannel.sendToOthers(client, new Data(reply));
      } catch (Exception e) {
        System.err.println("EditorServer: lockRequested: error sending lock denied");
        if (EditorServer_Debug) e.printStackTrace();
      }
    }
  }
Ejemplo n.º 10
0
 public void updateParagraphList() {
   documentPanel.parList.setModel(lockManager.getListModel());
 }