Creating real-time notepad in Java

Background: I would like to create a notebook application for notepad in which several people can edit one document / notepad. I have already created a graphical interface and now I want to start exploring part of its collaboration.

Questions: How to get text from one client text window to go to another client text field. Can I use sockets? Where can I save text to be used by all clients? What I will need to use / do to create a live text block in real time. What is a good starting point from which I can explore?

Examples: Etherpad.com/Titanpad.com/Piratepad.com or Docs.Google.com (in addition, I want to create a desktop application, not a website)

The solution of some questions that arose in the answers:

How do users select the document they want to change: Yes

How users create new documents: by selecting the "New file" option in the main menu

What happens if many users try to edit the same document at the same time ?: They are allowed to edit the document.

Does the user need to click the "Save" button before the changes are reflected ?: No, the changes must be reflected simultaneously

Do you need to log in ?: Yes

Can anyone edit any document or is there access restriction ?: There are restrictions, i.e. the document creator may prevent the user from editing documents ..

+5
source share
4 answers

. , , :

  • , ?
  • ?
  • , ?
  • "" , ?
  • ?
  • - ?

, , , , .

+2

etherpad. Collab_server.js. , . :

function applyUserChanges(pad, baseRev, changeset, optSocketId, optAuthor) {
  // changeset must be already adapted to the server apool

  var apool = pad.pool();
  var r = baseRev;
  while (r < pad.getHeadRevisionNumber()) {
    r++;
    var c = pad.getRevisionChangeset(r);
    changeset = Changeset.follow(c, changeset, false, apool);
  }

  var prevText = pad.text();
  if (Changeset.oldLen(changeset) != prevText.length) {
    _doWarn("Can't apply USER_CHANGES "+changeset+" to document of length "+
            prevText.length);
    return;
  }

  var thisAuthor = '';
  if (optSocketId) {
    var connectionId = getSocketConnectionId(optSocketId);
    if (connectionId) {
      var connection = getConnection(connectionId);
      if (connection) {
        thisAuthor = connection.data.userInfo.userId;
      }
    }
  }
  if (optAuthor) {
    thisAuthor = optAuthor;
  }

  pad.appendRevision(changeset, thisAuthor);
  var newRev = pad.getHeadRevisionNumber();
  if (optSocketId) {
    _getPadRevisionSockets(pad)[newRev] = optSocketId;
  }

  var correctionChangeset = _correctMarkersInPad(pad.atext(), pad.pool());
  if (correctionChangeset) {
    pad.appendRevision(correctionChangeset);
  }

  ///// make document end in blank line if it doesn't:
  if (pad.text().lastIndexOf("\n\n") != pad.text().length-2) {
    var nlChangeset = Changeset.makeSplice(
      pad.text(), pad.text().length-1, 0, "\n");
    pad.appendRevision(nlChangeset);
  }

  updatePadClients(pad);

  activepads.touch(pad.getId());
  padevents.onEditPad(pad, thisAuthor);
}

, .

0

, Google () Wave. .

0

All Articles