Ejemplo n.º 1
0
  /**
   * Creates a translation part of word card, it corresponds to one meaning.
   *
   * @return true if there are any translations in this translation block.
   */
  public boolean create(Connect conn, TTranslation _ttranslation, TLang _lang) {
    meaning_summary = _ttranslation.getMeaningSummary();

    TTranslationEntry[] trans_entries = TTranslationEntry.getByTranslation(conn, _ttranslation);
    // System.out.println("WCTranslation.create() _lang=" + _lang.getLanguage().toString() + ";
    // trans_entries.length=" + trans_entries);

    List<TranslationEntryItem> data_trans = new ArrayList();

    //  listview_trans.items length =" + trans_entries.length);
    trans_entry_items_size = trans_entries.length;
    // trans_entry_items = new TranslationEntryItem[trans_entries.length];
    for (int i = 0; i < trans_entries.length; i++) {
      TTranslationEntry e = trans_entries[i];

      LanguageType l = e.getLang().getLanguage();
      String lang_name_value = l.getName();
      String lang_code_value = l.getCode();
      String translation_text = e.getWikiText().getText();

      TranslationEntryItem item = new TranslationEntryItem();
      item.create(lang_name_value, lang_code_value, translation_text);
      data_trans.add(item);
    }
    //  TranslationEntryItem[] trans_entry_items = data_trans.toArray();
    // insert trans_entry_items into listview_trans.items;

    ObservableList<TranslationEntryItem> data = FXCollections.observableArrayList(data_trans);

    listview_trans.setCellFactory(
        new Callback<
            ListView<wiwordik.word_card.TranslationEntryItem>,
            ListCell<wiwordik.word_card.TranslationEntryItem>>() {
          @Override
          public ListCell<wiwordik.word_card.TranslationEntryItem> call(
              ListView<wiwordik.word_card.TranslationEntryItem> list) {
            return new wiwordik.word_card.TranslationCell();
          }
        });
    listview_trans.setItems(data);
    setMinMaxTranslationBoxHeight(listview_trans, data.size());

    // GUI                          right - indent for translation list words
    //                          top right bottom left
    group.setPadding(new Insets(0, 20, 0, 0));

    Text t_meaning_summary = new Text();
    t_meaning_summary.setText(meaning_summary);

    group.getChildren().addAll(t_meaning_summary);
    group.getChildren().addAll(listview_trans);

    return trans_entries.length > 0;
  }
Ejemplo n.º 2
0
  // float getTranslationBoxHeight(int n)
  void setMinMaxTranslationBoxHeight(ListView<TranslationEntryItem> listview_trans, int n) {
    float height;

    // assert: listview_trans.items.size == n > 0
    if (0 == n || n < 1) return; // this line is not reachable

    float h = TranslationEntryItem.getHeight(); // the height of one item
    // System.out.println("WCTranslation:setMinMaxTranslationBoxHeight() h = " + h);

    if (n > 0 && n <= 9) {
      height = n * h;

      listview_trans.setMinHeight(height);
      listview_trans.setMaxHeight(height);

      // System.out.println("variant a-small) n = " + n);
      return;
    }

    height = 7 * h; // too much entries
    listview_trans.setMinHeight(height);
    listview_trans.setMaxHeight(height);
    // System.out.println("variant a-huge) n = " + n);
  }