Exemplo n.º 1
0
  /**
   * Saves the translation in two steps. First, the all the paragraph objects are serialized and
   * stored in the .slon file. Second, the target text is saved in a plain text (.translated.txt)
   * file.
   */
  public void saveTranslation(JTable table) {
    /* If there is an unclosed segment, close it. */
    try {
      table.getCellEditor().stopCellEditing();
    } catch (Exception e1) {
      // do nothing
      // it is normal that if nothing is edited, editing can't be stopped
    }
    /* get the new translations */
    ListIterator<Paragraph> iteratorP = this.paragraphs.listIterator();
    Paragraph par = iteratorP.next();
    ListIterator<Segment> iteratorS = par.getSegments().listIterator();
    Segment seg = iteratorS.next();
    DefaultTableModel tbModel = (DefaultTableModel) table.getModel();
    for (int i = 0; i < paragraphs.size(); i++) {
      seg.getTarget().setText(tbModel.getValueAt(i, 1).toString());
      seg.setComment(tbModel.getValueAt(i, 2).toString());
      if (!iteratorS.hasNext()) {
        if (!iteratorP.hasNext()) {
          break;
        } else {
          par = iteratorP.next();
          iteratorS = par.getSegments().listIterator();
        }
      }
      seg = iteratorS.next();
    }
    /* serialization */
    try {
      serializeAll(project.translationFile.getAbsolutePath()); // all paragraphs
      // TODO check if the name of the file or the file itself is better
    } catch (IOException e) {
      e.printStackTrace();
    }
    /* writing to a monolingual target file */
    try {
      writeTarget(project.targetFile.getAbsolutePath()); // write to the .txt target file
      // TODO check if the name of the file or the file itself is better
    } catch (IOException e) {
      e.printStackTrace();
    }

    /* resetting variables */
    unsavedChanges = false;
  }
Exemplo n.º 2
0
  /**
   * Reads the Paragraph objects and displays them on the translation table
   *
   * @param table the translation table
   */
  private void showParagraphs(JTable table) {
    DefaultTableModel tblModel = (DefaultTableModel) table.getModel();

    ListIterator<Paragraph> iteratorP = paragraphs.listIterator();
    ListIterator<Segment> iteratorS;
    String sourceText;
    String targetText;
    String comment;

    while (iteratorP.hasNext()) {
      Paragraph par = iteratorP.next();
      iteratorS = par.getSegments().listIterator();
      while (iteratorS.hasNext()) {
        Segment seg = iteratorS.next();
        sourceText = seg.getSource().getText();
        targetText = seg.getTarget().getText();
        comment = seg.getComment();
        tblModel.addRow(new Object[] {sourceText, targetText, comment});
      }
    }
  }