1
2
3
4
5
6 package io.github.olyutorskii.quetexj;
7
8 import javax.swing.Action;
9 import javax.swing.BoundedRangeModel;
10 import javax.swing.DefaultBoundedRangeModel;
11 import javax.swing.JTextArea;
12 import javax.swing.JToggleButton.ToggleButtonModel;
13 import javax.swing.text.DefaultCaret;
14 import javax.swing.text.Document;
15 import javax.swing.text.PlainDocument;
16
17
18
19
20 public class MvcFacade {
21
22 private final Document document;
23 private final BoundedRangeModel vertRangeModel;
24 private final ToggleButtonModel trackSwitchButtonModel;
25
26 private final JTextArea textArea;
27
28 private final HeightKeeper heightKeeper;
29 private final MaxTracker maxTracker;
30
31 private final Action clearAction;
32
33
34
35
36
37
38
39
40 public MvcFacade() {
41 this(
42 new PlainDocument(),
43 new DefaultBoundedRangeModel(),
44 new ToggleButtonModel());
45 return;
46 }
47
48
49
50
51
52
53
54
55 public MvcFacade(
56 Document document,
57 BoundedRangeModel vertRangeModel,
58 ToggleButtonModel trackSwitchButtonModel) {
59 super();
60
61 this.document = document;
62 this.vertRangeModel = vertRangeModel;
63 this.trackSwitchButtonModel = trackSwitchButtonModel;
64
65 this.textArea = buildTextArea(this.document);
66
67 this.heightKeeper =
68 new HeightKeeper(this.textArea, this.vertRangeModel);
69 this.maxTracker =
70 new MaxTracker(
71 this.vertRangeModel, this.trackSwitchButtonModel);
72
73 this.clearAction = new ClearDocumentAction(this.document);
74
75 return;
76 }
77
78
79
80
81
82
83
84
85 private static JTextArea buildTextArea(Document doc) {
86 JTextArea textComp = new JTextArea();
87
88 textComp.setEditable(false);
89 textComp.setLineWrap(true);
90
91 DefaultCaret caret = new DefaultCaret();
92 caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
93 textComp.setCaret(caret);
94
95 textComp.setDocument(doc);
96
97 return textComp;
98 }
99
100
101
102
103
104
105
106 public Document getDocument() {
107 return this.document;
108 }
109
110
111
112
113
114
115 public JTextArea getTextArea() {
116 return this.textArea;
117 }
118
119
120
121
122
123
124 public BoundedRangeModel getVerticalBoundedRangeModel() {
125 return this.vertRangeModel;
126 }
127
128
129
130
131
132
133 public HeightKeeper getHeightKeeper() {
134 return this.heightKeeper;
135 }
136
137
138
139
140
141
142 public MaxTracker getMaxTracker() {
143 return this.maxTracker;
144 }
145
146
147
148
149
150
151 public ToggleButtonModel getTrackSwitchButtonModel() {
152 return this.trackSwitchButtonModel;
153 }
154
155
156
157
158
159
160 public Action getClearAction() {
161 return this.clearAction;
162 }
163
164 }