Beispiel #1
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();
    }
  }
Beispiel #2
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();
    }
  }
Beispiel #3
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();
    }
  }
Beispiel #4
0
 public void sendClientReject(int keyValue, int reason) {
   Message.ClientRejectMsg msg = new Message.ClientRejectMsg(-1, keyValue, reason);
   try {
     clientChannel.sendToOthers(client, new Data(msg));
   } catch (Exception e) {
     System.err.println("EditorServer: clientRejected: error sending msg");
     if (EditorServer_Debug) e.printStackTrace();
   }
 }
Beispiel #5
0
 public void scrollMoved(Message.ScrollMoveMsg m) {
   // if(EditorServer_Debug) System.err.println("EditorServer: scrollMoved.") ;
   try {
     clientChannel.sendToOthers(client, new Data(m));
   } catch (Exception e) {
     System.err.println("EditorServer: scrollMoved: error sending msg");
     if (EditorServer_Debug) e.printStackTrace();
   }
 }
Beispiel #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();
   }
 }
Beispiel #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();
    }
  }
Beispiel #8
0
  public void highlightDeleted(Message.HighlightDeleteMsg m) {
    if (EditorServer_Debug) System.err.println("EditorServer: highlightDeleted.");

    highlights.deleteHighlight(m.getId());
    EditorClient c = getEditorClient(m.getClientId());
    try {
      textChannel.sendToOthers(client, new Data(m));
    } catch (Exception e) {
      System.err.println("EditorServer: highlightDeleted: error sending msg");
      if (EditorServer_Debug) e.printStackTrace();
    }
  }
Beispiel #9
0
  public void highlightTypeAdded(Message.HighlightTypeMsg m) {
    if (EditorServer_Debug) System.err.println("EditorServer: highlightTypeAdded.");

    highlights.addHighlightType(m.getId(), m.getName(), m.getColor());

    try {
      textChannel.sendToOthers(client, new Data(m));
    } catch (Exception e) {
      System.err.println("EditorServer: highlightTypeAdded: error sending msg");
      if (EditorServer_Debug) e.printStackTrace();
    }
  }
Beispiel #10
0
  public void highlightEdited(Message.HighlightEditMsg m) {
    if (EditorServer_Debug) System.err.println("EditorServer: highlightEdited.");

    highlights.editHighlight(
        m.getId(), m.getStartPar(), m.getStartOffset(), m.getEndPar(), m.getEndOffset());

    try {
      textChannel.sendToOthers(client, new Data(m));
    } catch (Exception e) {
      System.err.println("EditorServer: highlightEdited: error sending msg");
      if (EditorServer_Debug) e.printStackTrace();
    }
  }
Beispiel #11
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();
      }
    }
  }
Beispiel #12
0
  public void clientLeft(Message.ClientLeaveMsg m) {
    System.out.println("EditorServer: clientLeft");

    EditorClient ec = getEditorClient(m.getClientId());
    ec.setPresent(false);
    clientsPanel.updateClientList();

    try {
      clientChannel.sendToOthers(client, new Data(m));
    } catch (Exception e) {
      System.err.println("EditorServer: clientLeft: error sending msg");
      if (EditorServer_Debug) e.printStackTrace();
    }
  }
Beispiel #13
0
  public void gestureLine(Message.GestureLineMsg m) {
    if (EditorServer_Debug)
      System.err.println("EditorServer: gestureLine." + String.valueOf(m.getId()));

    try {
      clientChannel.sendToOthers(client, new Data(m));
      EditorClient c = getEditorClient(m.getClientId());
      long par = getParIdForGesture(m.getPar(), m.getAY());
      c.addGestureAction(System.currentTimeMillis(), m.getId(), par, m.getAX(), m.getAY(), this);
      c.addGestureAction(System.currentTimeMillis(), m.getId(), par, m.getBX(), m.getBY(), this);
      clientsPanel.updateActionTableFor(c);
    } catch (Exception e) {
      System.err.println("EditorServer: gestureLine: error sending msg");
      if (EditorServer_Debug) e.printStackTrace();
    }
  }
Beispiel #14
0
  public void clientAppeared() {
    if (EditorServer_Debug) System.out.println("EditorServer: clientAppeared.");

    // send client list to everybody
    try {
      Iterator i = clients.iterator();

      while (i.hasNext()) {
        EditorClient ec = (EditorClient) i.next();
        if (ec.isPresent()) clientChannel.sendToOthers(client, new Data(ec.getMessage()));
      }

    } catch (Exception e) {
      System.err.println("EditorServer: clientAppeared: error sending msg");
      if (EditorServer_Debug) e.printStackTrace();
    }
  }
Beispiel #15
0
  public void sendHighlightTypes() {
    //      send highlightTypes to everybody
    try {
      Iterator i = highlights.getHighlightTypes().iterator();

      while (i.hasNext()) {
        HighlightType type = (HighlightType) i.next();

        if (EditorServer_Debug)
          System.out.println("EditorServer: sendHighlightTypes. " + String.valueOf(type.getId()));

        Message.HighlightTypeMsg msg =
            new Message.HighlightTypeMsg(-1, type.getId(), type.getName(), type.getColor());
        textChannel.sendToOthers(client, new Data(msg));
      }
    } catch (Exception e) {
      System.err.println("EditorServer: sendHighlightTypes: error sending msg");
      if (EditorServer_Debug) e.printStackTrace();
    }
  }
Beispiel #16
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();
    }
  }
Beispiel #17
0
  public void clientJoined(Message.ClientJoinMsg m) {

    Iterator i = clients.iterator();

    while (i.hasNext()) {
      EditorClient ec = (EditorClient) i.next();
      if (ec.isPresent()) {
        if (m.getName().equals(ec.getName())) {
          sendClientReject(m.getKeyValue(), Message.ClientRejectMsg.REASON_NAME);
          return;
        }
        if (m.getColorCode() == ec.getColorCode()) {
          sendClientReject(m.getKeyValue(), Message.ClientRejectMsg.REASON_COLOR);
          return;
        }
      }
    }

    // clientAccepted
    // mach... added ClientIPaddress + added server to EditorClient const
    EditorClient newClient =
        new EditorClient(
            this,
            nextClientId,
            m.getName(),
            m.getColorCode(),
            m.getKeyValue(),
            m.getClientIPaddress());

    if (EditorServer_Debug)
      System.out.println(
          ">>> In EditorServer.clientJoined  : client NAME is : *"
              + m.getName()
              + "* IPAddress : is : *"
              + m.getClientIPaddress()
              + "*");

    clients.add(newClient);
    nextClientId++;
    clientsPanel.updateClientList();

    // here... match Audio & Text client
    // iterate through list of audio client

    String audioClientIP = "";

    int offset = -1;

    if (isAudioOptionSelected) {

      if (EditorServer_Debug) System.out.println("\n>>>In Client Accepted !!!");

      for (int n = 0; n < plistModel.getSize(); n++) {

        audioClientIP = (plistModel.getElementAt(n)).toString();

        offset = audioClientIP.indexOf('@');

        audioClientIP = audioClientIP.substring(offset + 1);

        if (audioClientIP.equals(m.getClientIPaddress())) {

          System.out.println("MATCH found!!!" + m.getName() + "<>" + audioClientIP);

          // change ...

          plistModel.set(n, m.getName());
        }
      }
    } // endif isAudioOptionSelected

    try {
      clientChannel.sendToOthers(client, new Data(newClient.getMessage()));
      sendDocumentState(nextClientId - 1);
      sendHighlightTypes();
      sendHighlights();
    } catch (Exception e) {
      System.err.println("EditorServer: clientJoined: error sending msg");
      if (EditorServer_Debug) e.printStackTrace();
    }
  }