44import javafx .event .ActionEvent ;
55import javafx .fxml .FXML ;
66import javafx .scene .Node ;
7- import javafx .scene .control .Button ;
8- import javafx .scene .control . RadioButton ;
9- import javafx .scene .control . TextField ;
7+ import javafx .scene .control .* ;
8+ import javafx .scene .image . Image ;
9+ import javafx .scene .image . ImageView ;
1010import javafx .scene .layout .*;
1111import javafx .scene .paint .Color ;
1212
@@ -39,9 +39,13 @@ public class Controller {
3939 private TextField hexString ;
4040 @ FXML
4141 private Button drawButton ;
42+ @ FXML
43+ private MenuItem aboutDialog ;
4244
4345 @ FXML
4446 private void initialize () {
47+ // show AboutDialog
48+ aboutDialog .setOnAction (event -> showAbout ());
4549
4650 // Handle 5x8 radio button event
4751 rbutton58 .setOnAction (event -> createEmptyMatrix (8 , 5 ));
@@ -74,6 +78,21 @@ private void initialize() {
7478 createEmptyMatrix (8 , 5 );
7579 }
7680
81+ /**
82+ * Show promotion
83+ */
84+ private void showAbout () {
85+ String uri = "www.ant.ee" ;
86+ Alert alert = new Alert (Alert .AlertType .INFORMATION );
87+ alert .setTitle ("About author" );
88+ alert .setHeaderText ("" );
89+ alert .setGraphic (new ImageView (new Image ("ant.png" )));
90+ Hyperlink link = new Hyperlink (uri );
91+ link .setOnAction (event -> Main .openURL (uri + "/?dotmatrix" ));
92+ alert .getDialogPane ().contentProperty ().set (link );
93+ alert .showAndWait ();
94+ }
95+
7796 /**
7897 * Draw empty matrix and register draw events
7998 *
@@ -82,6 +101,7 @@ private void initialize() {
82101 */
83102 private void createEmptyMatrix (int rows , int columns ) {
84103 dotMatrix .getChildren ().clear ();
104+ hexString .clear ();
85105 for (int i = 0 ; i < columns ; i ++) {
86106 for (int j = 0 ; j < rows ; j ++) {
87107 Button btn = new Button ();
@@ -146,23 +166,45 @@ private void parseHexString(String text) {
146166 }
147167
148168 /**
149- * Draw symbol from bytes array
169+ * Draw symbol from bytes array. It can be either single segment or 4 segments if number of bytes is
170+ * grater than 8
150171 *
151172 * @param bytes byte array that encodes symbol
152173 */
153174 private void fillMatrixWithDots (byte [] bytes ) {
175+ int colums = bytes .length ;
154176 if (bytes .length > 8 ) {
155177 // there are 4 segments
156- createEmptyMatrix (16 , bytes .length / 2 );
178+ colums = bytes .length / 2 ;
179+ createEmptyMatrix (16 , colums );
157180 drawSegment (0 , 0 , Arrays .copyOfRange (bytes , 0 , bytes .length / 4 ));
158181 drawSegment (0 , bytes .length / 4 , Arrays .copyOfRange (bytes , bytes .length / 4 , bytes .length / 2 ));
159182 drawSegment (8 , 0 , Arrays .copyOfRange (bytes , bytes .length / 2 , 3 * bytes .length / 4 ));
160183 drawSegment (8 , bytes .length / 4 , Arrays .copyOfRange (bytes , 3 * bytes .length / 4 , bytes .length ));
161184 } else {
162185 // there is only one segment
163- createEmptyMatrix (8 , bytes . length );
186+ createEmptyMatrix (8 , colums );
164187 drawSegment (bytes );
165188 }
189+
190+ // select radiobutton of corresponding size
191+ switch (colums ) {
192+ case 5 : rbutton58 .setSelected (true );
193+ break ;
194+ case 6 : rbutton68 .setSelected (true );
195+ break ;
196+ case 7 : rbutton78 .setSelected (true );
197+ break ;
198+ case 8 : rbutton88 .setSelected (true );
199+ break ;
200+ case 10 : rbutton1016 .setSelected (true );
201+ break ;
202+ case 12 : rbutton1216 .setSelected (true );
203+ break ;
204+ case 14 : rbutton1416 .setSelected (true );
205+ break ;
206+ case 16 : rbutton1616 .setSelected (true );
207+ }
166208 }
167209
168210 /**
@@ -183,7 +225,8 @@ private void drawSegment(byte[] bytes) {
183225 }
184226
185227 /**
186- * Draw segment based on offset. Top left has 0,0 and bottom right 8, number of columns
228+ * Draw segment based on offset. Top left has 0,0 and bottom right 8, number of columns. Used
229+ * for multi-segment character
187230 *
188231 * @param offsetCol - column offset
189232 * @param offsetRaw - raw offset
@@ -223,7 +266,9 @@ private void generateHexString() {
223266 }
224267
225268 /**
226- * Create hex string for selected segment
269+ * Create hex string for segment based on offset. Used for multi-segment
270+ * hex string calculation
271+ *
227272 * @param offsetCol column offset
228273 * @param offsetRaw raw offset
229274 * @return hex string for the segment
@@ -241,7 +286,7 @@ private char[] readSegment(int offsetCol, int offsetRaw) {
241286 }
242287
243288 /**
244- * Return hex string for single segment 8*columns
289+ * Calculates hex codes and return string for single segment 8*columns
245290 * @param segment buttons node list in a segment
246291 * @return hex string
247292 */
0 commit comments