Exemple #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";
  }
Exemple #2
0
  public boolean loadDocument(String fileName) {
    try {
      File file = new File(fileName);
      ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
      SavedDocument doc = (SavedDocument) in.readObject();

      document =
          new EditorDocument(
              doc.getTitle(), doc.getDescription(),
              doc.getText(), doc.getStartTime());
      paragraphs = new Paragraphs(document, doc.getParagraphsVector());
      clients = doc.getClients();
      Iterator i = clients.iterator();
      while (i.hasNext()) {
        EditorClient c = (EditorClient) i.next();
        c.setPresent(false);

        if (c.getIdNumber() > nextClientId) nextClientId = c.getIdNumber();
      }
      nextClientId++;

      lockManager = new LockManager(clients, document, paragraphs);
      highlights =
          new Highlights(lockManager, document, doc.getHighlightTypes(), doc.getHighlights());

      return true;
    } catch (Exception e) {
      System.out.println("EditorServer: loadDocument. error");
      e.printStackTrace();
      return false;
    }
  } // endof const WITH audio profile maker
Exemple #3
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();
    }
  }
Exemple #4
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();
    }
  }
Exemple #5
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();
    }
  }
Exemple #6
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();
   }
 }
Exemple #7
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();
   }
 }
Exemple #8
0
 public int getYValueFromOffset(int offset) {
   try {
     return textPane.modelToView(offset).y;
   } catch (Exception e) {
     System.out.println("EditorServer: DocumentPanel: getYValueFromOffset. error");
     e.printStackTrace();
     return 0;
   }
 }
Exemple #9
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();
   }
 }
Exemple #10
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();
    }
  }
Exemple #11
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();
    }
  }
Exemple #12
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();
    }
  }
Exemple #13
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();
    }
  }
Exemple #14
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();
    }
  }
Exemple #15
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();
    }
  }
Exemple #16
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();
    }
  }
Exemple #17
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();
    }
  }
Exemple #18
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();
    }
  }
Exemple #19
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();
      }
    }
  }
Exemple #20
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();
    }
  }