summaryrefslogtreecommitdiff
path: root/dicore3/command/src/main/java/io/dico/dicore/command/chat/help/PageBorders.java
blob: cd105b132a15552a6931d2473b0013c64f7bd069 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package io.dico.dicore.command.chat.help;

import java.util.Arrays;

public class PageBorders {
    private final IPageBorder header, footer;

    public PageBorders(IPageBorder header, IPageBorder footer) {
        this.header = header;
        this.footer = footer;
    }

    public IPageBorder getHeader() {
        return header;
    }

    public IPageBorder getFooter() {
        return footer;
    }

    public static IPageBorder simpleBorder(String... lines) {
        return new SimplePageBorder(lines);
    }

    public static IPageBorder disappearingBorder(int pageNum, String... lines) {
        return disappearingBorder(pageNum, 0, lines);
    }

    public static IPageBorder disappearingBorder(int pageNum, int keptLines, String... lines) {
        return new DisappearingPageBorder(pageNum, keptLines, lines);
    }

    static class SimplePageBorder extends SimpleHelpComponent implements IPageBorder {
        private final String replacedSequence;

        public SimplePageBorder(String replacedSequence, String... lines) {
            super(lines);
            this.replacedSequence = replacedSequence;
        }

        public SimplePageBorder(String... lines) {
            super(lines);
            this.replacedSequence = "%pageCount%";
        }

        @Override
        public void setPageCount(int pageCount) {
            String[] lines = this.lines;
            for (int i = 0; i < lines.length; i++) {
                lines[i] = lines[i].replace(replacedSequence, Integer.toString(pageCount));
            }
        }

    }

    static class DisappearingPageBorder extends SimpleHelpComponent implements IPageBorder {
        private final int pageNum;
        private final int keptLines;

        public DisappearingPageBorder(int pageNum, int keptLines, String... lines) {
            super(lines);
            this.pageNum = pageNum;
            this.keptLines = keptLines;
        }

        @Override
        public void setPageCount(int pageCount) {
            if (pageCount == pageNum) {
                String[] lines = this.lines;
                this.lines = Arrays.copyOfRange(lines, Math.max(0, lines.length - keptLines), lines.length);
            }
        }

    }

}