View Javadoc

1   package com.jpeterson.virtlcd.swing;
2   
3   import javax.swing.JComponent;
4   import javax.swing.UIManager;
5   
6   import com.jpeterson.virtlcd.swing.ui.BasicDotMatrixSixByEightUI;
7   import com.jpeterson.virtlcd.swing.ui.DotMatrixSixByEightUI;
8   
9   /**
10   * Basic LCD character display. As the name suggests, the characters are
11   * composed of six pixels across and eight pixels down.
12   * 
13   * @author Jesse Peterson
14   * @see JDotMatrixDisplay
15   */
16  public class JDotMatrixSixByEight extends JComponent {
17  	/**
18  	 * 
19  	 */
20  	private static final long serialVersionUID = 1L;
21  
22  	/**
23  	 * The UI class ID string.
24  	 */
25  	private static final String uiClassID = "DotMatrixSixByEightUI";
26  
27  	protected DotMatrixModel model;
28  
29  	/**
30  	 * Construct a new component that will display 1 character.
31  	 */
32  	public JDotMatrixSixByEight() {
33  		this.model = new DefaultDotMatrixModel();
34  
35  		this.updateUI();
36  	}
37  
38  	/**
39  	 * Sets the new UI delegate.
40  	 * 
41  	 * @param ui
42  	 *            New UI delegate.
43  	 */
44  	public void setUI(DotMatrixSixByEightUI ui) {
45  		super.setUI(ui);
46  	}
47  
48  	/**
49  	 * Resets the UI property to a value from the current look and feel.
50  	 * 
51  	 * @see JComponent#updateUI
52  	 */
53  	public void updateUI() {
54  		if (UIManager.get(getUIClassID()) != null) {
55  			setUI((DotMatrixSixByEightUI) UIManager.getUI(this));
56  		} else {
57  			setUI(new BasicDotMatrixSixByEightUI());
58  		}
59  	}
60  
61  	/**
62  	 * Returns the UI object which implements the L&F for this component.
63  	 * 
64  	 * @return UI object which implements the L&F for this component.
65  	 * @see #setUI
66  	 */
67  	public DotMatrixSixByEightUI getUI() {
68  		return (DotMatrixSixByEightUI) ui;
69  	}
70  
71  	/**
72  	 * Returns the name of the UI class that implements the L&F for this
73  	 * component.
74  	 * 
75  	 * @return The name of the UI class that implements the L&F for this
76  	 *         component.
77  	 * @see JComponent#getUIClassID
78  	 * @see UIDefaults#getUI
79  	 */
80  	public String getUIClassID() {
81  		return uiClassID;
82  	}
83  
84  	public DotMatrixModel getModel() {
85  		return this.model;
86  	}
87  
88  	/**
89  	 * Get the character displayed.
90  	 * 
91  	 * @return The character displayed.
92  	 */
93  	public char getChar() {
94  		return model.getChar();
95  	}
96  
97  	/**
98  	 * Set the character to display.
99  	 * 
100 	 * @param c
101 	 *            the character to display.
102 	 */
103 	public void setChar(char c) {
104 		char oldC = model.getChar();
105 		if (oldC != c) {
106 			model.setChar(c);
107 		}
108 	}
109 }