コード例 #1
0
ファイル: EditorServer.java プロジェクト: amarala/recoled
  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();
    }
  }
コード例 #2
0
ファイル: EditorServer.java プロジェクト: amarala/recoled
  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();
    }
  }
コード例 #3
0
ファイル: EditorServer.java プロジェクト: amarala/recoled
  public EditorServer(String fileName, String name, String desc) {
    super();
    self = this;
    if (fileName == null || !loadDocument(fileName)) {
      clients = new Vector();
      document = new EditorDocument(name, desc, "", System.currentTimeMillis());

      try {
        // ascii code for first blue line...
        document.insertString(0, "·-·+·*=·x·\n", document.getStyle("line"));
      } catch (BadLocationException ble) {
        System.out.println("EditorServer->const: BadLocationException");
      }

      paragraphs = new Paragraphs(document);
      lockManager = new LockManager(clients, document, paragraphs);
      highlights = new Highlights(lockManager, document);

      nextClientId = 1;
    }

    isAudioOptionSelected = false;
    // to avoid unecessary Audio - Text participant matching

    documentPanel = new DocumentPanel();
    updateParagraphList();

    clientsPanel = new ClientsPanel();
    clientsPanel.updateClientList();

    Icon clockIcon = getImageIcon("images/clock.gif");

    Icon clockIcon2 = getImageIcon("images/clock2.gif");

    startRTPrecording = new JButton("START RTP Recording", clockIcon);

    startRTPrecording.setRolloverIcon(clockIcon2);

    RecordingHandler recHandler = new RecordingHandler(self);

    startRTPrecording.addActionListener(recHandler);

    Icon stopIcon = getImageIcon("images/stop.gif");

    stopRTPrecording = new JButton("STOP RTP recording", stopIcon);

    stopRTPrecording.setEnabled(false);

    stopRTPrecording.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {

            recorder.endRecording();

            stopRTPrecording.setEnabled(false);
            startRTPrecording.setEnabled(true);
          }
        });

    Container container = getContentPane();

    container.setLayout(new FlowLayout());

    container.add(startRTPrecording);
    container.add(stopRTPrecording);

    // JTabbedPane tabPane = new JTabbedPane() ;
    tabPane.add("Document", documentPanel);
    tabPane.add("Text Clients", clientsPanel);
    container.add(tabPane, BorderLayout.CENTER);

    setTitle("EditorServer");
    setSize(new Dimension(800, 600));

    addWindowListener(
        new WindowAdapter() {

          public void windowClosing(WindowEvent e) {
            lockManager.saveDocument(null, highlights, self);
            System.exit(0);
          }
        });

    JMenuItem mnuSave = new JMenuItem("Save");
    mnuSave.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            JFileChooser dialog = new JFileChooser();
            dialog.addChoosableFileFilter(
                new MyFileFilter("Collabortive Document File (*.cde)", ".cde"));
            dialog.setAcceptAllFileFilterUsed(false);

            if (dialog.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
              lockManager.saveDocument(dialog.getSelectedFile().getPath(), highlights, self);
            }
          }
        });

    JMenuItem mnuSaveXML = new JMenuItem("Save XML");
    mnuSaveXML.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            JFileChooser dialog = new JFileChooser();
            dialog.addChoosableFileFilter(new MyFileFilter("XML File (*.xml)", ".xml"));
            dialog.setAcceptAllFileFilterUsed(false);

            if (dialog.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
              lockManager.saveXML(dialog.getSelectedFile().getPath(), highlights, self);
            }
          }
        });

    JMenu mnuFile = new JMenu("File");
    mnuFile.add(mnuSave);
    mnuFile.add(mnuSaveXML);
    JMenuBar menu = new JMenuBar();
    menu.add(mnuFile);
    setJMenuBar(menu);

    Thread backupThread =
        new Thread() {
          public void run() {
            while (1 == 1) {
              yield();
              try {
                // sleep(1000) ;
                sleep(5 * 60 * 1000);
                lockManager.saveDocument(null, highlights, self);
              } catch (Exception e) {
                System.out.println("EditorServer: backupThread. error");
                e.printStackTrace();
              }
            }
          }
        };
    backupThread.setDaemon(true);
    backupThread.start();
  } // endof const WITHOUT audio profile maker