Пример #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";
  }
Пример #2
0
  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