Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
SystemMessagesTextPane |
|
| 1.8;1.8 |
1 | /****************************************************************************** | |
2 | * SystemMessagesTextPane.java - Display decorated text messages to the user. | |
3 | * $Id$ | |
4 | * | |
5 | * BuckoFIBS - Backgammon by BuckoSoft | |
6 | * Copyright© 2009,2010 - Dick Balaska - BuckoSoft, Corp. | |
7 | * | |
8 | * $Log$ | |
9 | * Revision 1.2 2010/03/03 12:19:49 inim | |
10 | * Moved source to UTF8 encoding from CP1252 encoding. To this end all source files' (c) message was updated to "Copyright© 2009,2010 - Dick Balaska - BuckoSoft, Corp.". This replaces the (c) sign to UTF8, and adds the new year 2010. | |
11 | * | |
12 | * Revision 1.1 2010/02/04 05:57:53 inim | |
13 | * Mavenized project folder layout | |
14 | * | |
15 | * Revision 1.6 2009/02/14 13:25:05 dick | |
16 | * BuckoFIBS is released under the GNU license. | |
17 | * Javadoc. | |
18 | * | |
19 | * Revision 1.5 2009/01/28 19:42:09 dick | |
20 | * Prettier cvs link in the javadoc. | |
21 | * | |
22 | * Revision 1.4 2008/12/11 10:00:48 dick | |
23 | * Differentiate between networkin and networkmsg, which display in different colors. | |
24 | * | |
25 | * Revision 1.3 2008/12/10 18:06:26 dick | |
26 | * Display messages with decorations. | |
27 | * | |
28 | * Revision 1.2 2008/12/09 01:52:20 dick | |
29 | * Set the font to monospaced. | |
30 | * | |
31 | * Revision 1.1 2008/03/30 05:43:29 dick | |
32 | * The window that gets system messages printed to it. | |
33 | */ | |
34 | ||
35 | /* | |
36 | * This program is free software: you can redistribute it and/or modify | |
37 | * it under the terms of the GNU General Public License as published by | |
38 | * the Free Software Foundation, either version 3 of the License, or | |
39 | * (at your option) any later version. | |
40 | * | |
41 | * This program is distributed in the hope that it will be useful, | |
42 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
43 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
44 | * GNU General Public License for more details. | |
45 | * | |
46 | * You should have received a copy of the GNU General Public License | |
47 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
48 | * | |
49 | * The Original Code is BuckoFIBS, <http://www.buckosoft.com/BuckoFIBS/>. | |
50 | * The Initial Developer of the Original Code is Dick Balaska and BuckoSoft, Corp. | |
51 | * | |
52 | */ | |
53 | package com.buckosoft.fibs.BuckoFIBS.gui; | |
54 | ||
55 | import java.awt.Color; | |
56 | ||
57 | import javax.swing.JTextPane; | |
58 | import javax.swing.text.BadLocationException; | |
59 | import javax.swing.text.Style; | |
60 | import javax.swing.text.StyleConstants; | |
61 | import javax.swing.text.StyleContext; | |
62 | import javax.swing.text.StyledDocument; | |
63 | ||
64 | /** Display decorated text messages to the user. | |
65 | * @author Dick Balaska | |
66 | * @since 2008/03/30 | |
67 | * @version $Revision$ <br> $Date$ | |
68 | * @see <a href="http://cvs.buckosoft.com/Projects/BuckoFIBS/BuckoFIBS/src/com/buckosoft/fibs/BuckoFIBS/gui/SystemMessagesTextPane.java">cvs SystemMessagesTextPane.java</a> | |
69 | */ | |
70 | public class SystemMessagesTextPane extends JTextPane { | |
71 | private static final long serialVersionUID = 1L; | |
72 | ||
73 | /** Regular text */ | |
74 | public static final int NORMAL = 0; | |
75 | /** monospaced, yellowish */ | |
76 | public static final int NETWORKIN = 1; | |
77 | /** monospaced, in a brownish hue */ | |
78 | public static final int NETWORKOUT = 2; | |
79 | /** monospaced */ | |
80 | public static final int NETWORKMSG = 3; | |
81 | public static final int ITALIC = 4; | |
82 | public static final int BOLD = 5; | |
83 | public static final int LARGE = 6; | |
84 | public static final int DEBUG = 7; | |
85 | /** Display text in red */ | |
86 | public static final int ERROR = 8; | |
87 | ||
88 | private static final int LAST = 9; | |
89 | ||
90 | private StyledDocument document; | |
91 | ||
92 | 0 | private Style[] styles = new Style[LAST]; |
93 | ||
94 | /** Create a SystemMessagesTextPane | |
95 | */ | |
96 | 0 | public SystemMessagesTextPane() { |
97 | 0 | document = this.getStyledDocument(); |
98 | 0 | addStylesToDocument(document); |
99 | 0 | initialize(); |
100 | 0 | } |
101 | ||
102 | /** | |
103 | * This method initializes this | |
104 | * | |
105 | */ | |
106 | private void initialize() { | |
107 | ||
108 | 0 | } |
109 | ||
110 | private void addStylesToDocument(StyledDocument doc) { | |
111 | // Initialize some styles. | |
112 | 0 | Style def = StyleContext.getDefaultStyleContext().getStyle( |
113 | StyleContext.DEFAULT_STYLE); | |
114 | ||
115 | 0 | styles[NORMAL] = doc.addStyle("regular", def); |
116 | ||
117 | 0 | styles[ITALIC] = doc.addStyle("italic", styles[NORMAL]); |
118 | 0 | StyleConstants.setItalic(styles[ITALIC], true); |
119 | ||
120 | 0 | styles[BOLD] = doc.addStyle("bold", styles[NORMAL]); |
121 | 0 | StyleConstants.setBold(styles[BOLD], true); |
122 | ||
123 | 0 | styles[LARGE] = doc.addStyle("large", styles[NORMAL]); |
124 | 0 | StyleConstants.setFontSize(styles[LARGE], 16); |
125 | ||
126 | 0 | styles[NETWORKIN] = doc.addStyle("fixed", styles[NORMAL]); |
127 | 0 | StyleConstants.setFontFamily(styles[NETWORKIN], "Monospaced"); |
128 | 0 | StyleConstants.setForeground(styles[NETWORKIN], new Color(0,153,255)); |
129 | ||
130 | 0 | styles[NETWORKOUT] = doc.addStyle("fixed", styles[NORMAL]); |
131 | 0 | StyleConstants.setFontFamily(styles[NETWORKOUT], "Monospaced"); |
132 | 0 | StyleConstants.setForeground(styles[NETWORKOUT], new Color(153,126,87)); |
133 | ||
134 | 0 | styles[NETWORKMSG] = doc.addStyle("fixed", styles[NORMAL]); |
135 | 0 | StyleConstants.setFontFamily(styles[NETWORKMSG], "Monospaced"); |
136 | ||
137 | 0 | styles[DEBUG] = doc.addStyle("debug", styles[NORMAL]); |
138 | 0 | StyleConstants.setFontFamily(styles[DEBUG], "Monospaced"); |
139 | 0 | StyleConstants.setForeground(styles[DEBUG], new Color(151,51,189)); |
140 | ||
141 | 0 | styles[ERROR] = doc.addStyle("fixed", styles[NORMAL]); |
142 | 0 | StyleConstants.setFontFamily(styles[ERROR], "Monospaced"); |
143 | 0 | StyleConstants.setForeground(styles[ERROR], Color.red); |
144 | ||
145 | 0 | } |
146 | ||
147 | /** Append a message to the bottom of the pane in the NORMAL style | |
148 | * @param s The message to append | |
149 | */ | |
150 | public void appendMessage(String s) { | |
151 | try { | |
152 | 0 | this.document.insertString(this.document.getLength(), s, styles[NORMAL]); |
153 | 0 | } catch (BadLocationException e) { |
154 | 0 | e.printStackTrace(); |
155 | 0 | } |
156 | 0 | } |
157 | ||
158 | /** Append a message to the bottom of the pane in this style | |
159 | * @param style The style to draw this message in. | |
160 | * @param s The message to append | |
161 | */ | |
162 | public void appendMessage(int style, String s) { | |
163 | 0 | if (style < 0 || style > LAST) |
164 | 0 | style = NORMAL; |
165 | try { | |
166 | 0 | this.document.insertString(this.document.getLength(), s, styles[style]); |
167 | 0 | } catch (BadLocationException e) { |
168 | 0 | e.printStackTrace(); |
169 | 0 | } |
170 | 0 | } |
171 | } |