+
+ // -3 because 0-based and 2 for borders
+ int row = getHeight() - 3;
+
+ String name = chapterName.getLabel();
+ while (name.length() < resize.getWidth() - chapterName.getX()) {
+ name += " ";
+ }
+ chapterName.setLabel(name);
+ chapterName.setWidth(resize.getWidth() - 10);
+ chapterName.setY(row);
+
+ for (TButton button : navigationButtons) {
+ button.setY(row);
+ }
+ }
+
+ private void setChapter(int chapter) {
+ if (chapter < 0) {
+ chapter = 0;
+ }
+
+ if (chapter > getStory().getChapters().size()) {
+ chapter = getStory().getChapters().size();
+ }
+
+ if (chapter != this.chapter) {
+ this.chapter = chapter;
+
+ int max = getStory().getChapters().size();
+ navigationButtons.get(0).setEnabled(chapter > 0);
+ navigationButtons.get(1).setEnabled(chapter > 0);
+ navigationButtons.get(2).setEnabled(chapter > 0);
+ navigationButtons.get(3).setEnabled(chapter < max);
+ navigationButtons.get(4).setEnabled(chapter < max);
+
+ Chapter chap;
+ String name;
+ if (chapter == 0) {
+ chap = getStory().getMeta().getResume();
+ name = String.format(" %s", chap.getName());
+ } else {
+ chap = getStory().getChapters().get(chapter - 1);
+ name = String
+ .format(" %d/%d: %s", chapter, max, chap.getName());
+ }
+
+ while (name.length() < getWidth() - chapterName.getX()) {
+ name += " ";
+ }
+
+ chapterName.setLabel(name);
+
+ StringBuilder builder = new StringBuilder();
+ // TODO: i18n
+ String c = String.format("Chapter %d: %s", chapter, chap.getName());
+ builder.append(c).append("\n");
+ for (int i = 0; i < c.length(); i++) {
+ builder.append("═");
+ }
+ builder.append("\n\n");
+ for (Paragraph para : chap) {
+ builder.append(para.getContent()).append("\n\n");
+ }
+ textField.setText(builder.toString());
+ textField.reflow();
+ textField.toTop();
+ }