1 package com.jpeterson.virtlcd.swing;
2
3 import javax.swing.JComponent;
4 import javax.swing.UIDefaults;
5 import javax.swing.UIManager;
6
7 import com.jpeterson.virtlcd.swing.ui.BasicDotMatrixDisplayUI;
8 import com.jpeterson.virtlcd.swing.ui.DotMatrixDisplayUI;
9
10
11
12
13
14
15
16
17
18 public class JDotMatrixDisplay extends JComponent {
19
20
21
22 private static final long serialVersionUID = 1L;
23
24
25
26
27 private static final String uiClassID = "DotMatrixDisplayUI";
28
29 protected DotMatrixDisplayModel model;
30
31 private int columns;
32
33 private int rows;
34
35
36
37
38
39
40
41
42
43
44
45 public JDotMatrixDisplay(int columns, int rows)
46 throws IllegalArgumentException {
47 this.model = new DefaultDotMatrixDisplayModel();
48
49 setColumns(columns);
50 setRows(rows);
51
52 this.updateUI();
53 }
54
55
56
57
58
59
60 public int getColumns() {
61 return columns;
62 }
63
64
65
66
67
68
69
70
71
72 private void setColumns(int columns) throws IllegalArgumentException {
73 if (columns <= 0) {
74 throw new IllegalArgumentException(
75 "Number of columns must be greater than zero");
76 }
77
78 this.columns = columns;
79 }
80
81
82
83
84
85
86 public int getRows() {
87 return rows;
88 }
89
90
91
92
93
94
95
96
97
98 private void setRows(int rows) throws IllegalArgumentException {
99 if (rows <= 0) {
100 throw new IllegalArgumentException(
101 "Number of rows must be greater than zero");
102 }
103
104 this.rows = rows;
105 }
106
107
108
109
110
111
112
113 public void setUI(DotMatrixDisplayUI ui) {
114 super.setUI(ui);
115 }
116
117
118
119
120
121
122 public void updateUI() {
123 if (UIManager.get(getUIClassID()) != null) {
124 setUI((DotMatrixDisplayUI) UIManager.getUI(this));
125 } else {
126 setUI(new BasicDotMatrixDisplayUI());
127 }
128 }
129
130
131
132
133
134
135
136 public DotMatrixDisplayUI getUI() {
137 return (DotMatrixDisplayUI) ui;
138 }
139
140
141
142
143
144
145
146
147
148
149 public String getUIClassID() {
150 return uiClassID;
151 }
152
153 public DotMatrixDisplayModel getModel() {
154 return this.model;
155 }
156
157
158
159
160
161
162 public String getText() {
163 return model.getText();
164 }
165
166
167
168
169
170
171
172
173
174
175 public void setText(String text) {
176 model.setText(text);
177 }
178 }