Coverage report

| %line | %branch
--- | --- | ---
tsukuba_bunko.peko.session.SaveDataInfoRenderer |
0% |
0% |

1 |  |
     /*
2 |  |
      * All Rights Reserved.
3 |  |
      * Copyright (C) 1999-2005 Tsukuba Bunko.
4 |  |
      *
5 |  |
      * Licensed under the BSD License ("the License"); you may not use
6 |  |
      * this file except in compliance with the License.
7 |  |
      * You may obtain a copy of the License at
8 |  |
      *
9 |  |
      *       http://www.tsukuba-bunko.org/licenses/LICENSE.txt
10 |  |
      *
11 |  |
      * Unless required by applicable law or agreed to in writing, software
12 |  |
      * distributed under the License is distributed on an "AS IS" BASIS,
13 |  |
      * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 |  |
      * See the License for the specific language governing permissions and
15 |  |
      * limitations under the License.
16 |  |
      *
17 |  |
      * $Id: SaveDataInfoRenderer.java,v 1.2 2005/07/23 19:01:33 ppoi Exp $
18 |  |
      */
19 |  |
     package tsukuba_bunko.peko.session;
20 |  |
21 |  |
     import	java.awt.Color;
22 |  |
     import	java.awt.Component;
23 |  |
     import	java.awt.Dimension;
24 |  |
     import	java.awt.Font;
25 |  |
     import	java.awt.Graphics;
26 |  |
     import	java.awt.Graphics2D;
27 |  |
     import	java.awt.RenderingHints;
28 |  |
29 |  |
     import	java.awt.font.TextAttribute;
30 |  |
     import	java.awt.font.TextLayout;
31 |  |
32 |  |
     import	java.text.AttributedString;
33 |  |
     import	java.text.MessageFormat;
34 |  |
     import	java.text.SimpleDateFormat;
35 |  |
36 |  |
     import	java.util.Map;
37 |  |
38 |  |
     import	javax.swing.BorderFactory;
39 |  |
     import javax.swing.JComponent;
40 |  |
     import	javax.swing.JList;
41 |  |
     import	javax.swing.ListCellRenderer;
42 |  |
43 |  |
     import	tsukuba_bunko.peko.Logger;
44 |  |
45 |  |
     import	tsukuba_bunko.peko.resource.ResourceManager;
46 |  |
     import	tsukuba_bunko.peko.resource.ColorManager;
47 |  |
     import	tsukuba_bunko.peko.resource.FontManager;
48 |  |
49 |  |
50 |  |
     /**
51 |  |
      * セーブデータ情報を描画する <code>ListCellRenderer</code> です。
52 |  |
      * @author	$Author: ppoi $
53 |  |
      * @version	$Revision: 1.2 $
54 |  |
      */
55 |  |
     public class SaveDataInfoRenderer	extends JComponent	implements ListCellRenderer	{
56 |  |
57 |  |
     	/**
58 |  |
     	 * serial version UID
59 |  |
     	 */
60 |  |
     	private static final long	serialVersionUID	= 2614501005677152982L;
61 |  |
62 |  |
     	/**
63 |  |
     	 * 描画するセーブデータ情報
64 |  |
     	 */
65 | 0 |
     	private SaveDataInfo	_info = null;
66 |  |
67 |  |
     	/**
68 |  |
     	 * 選択されているかどうか
69 |  |
     	 */
70 | 0 |
     	private boolean	_selected = false;
71 |  |
72 |  |
     	/**
73 |  |
     	 */
74 | 0 |
     	private int	_index = -1;
75 |  |
76 |  |
     	/**
77 |  |
     	 * 選択時の背景色
78 |  |
     	 */
79 | 0 |
     	private Color	_selectedBackground = null;
80 |  |
81 |  |
     	/**
82 |  |
     	 * 非選択時の背景色
83 |  |
     	 */
84 | 0 |
     	private Color	_unselectedBackground = null;
85 |  |
86 |  |
     	/**
87 |  |
     	 * タイトルフォント
88 |  |
     	 */
89 | 0 |
     	private Font	_titleFont = null;
90 |  |
91 |  |
     	/**
92 |  |
     	 * タイトル前景色
93 |  |
     	 */
94 | 0 |
     	private Color	_titleColor = null;
95 |  |
96 |  |
     	/**
97 |  |
     	 * タイムスタンプフォント
98 |  |
     	 */
99 | 0 |
     	private Font	_timestampFont = null;
100 |  |
101 |  |
     	/**
102 |  |
     	 * タイムスタンプ前景色
103 |  |
     	 */
104 | 0 |
     	private Color	_timestampColor = null;
105 |  |
106 |  |
     	/**
107 |  |
     	 * コメントフォント
108 |  |
     	 */
109 | 0 |
     	private Font	_commentFont = null;
110 |  |
111 |  |
     	/**
112 |  |
     	 * コメント前景色
113 |  |
     	 */
114 |  |
     	private Color	_commentColor;
115 |  |
116 |  |
117 |  |
     	/**
118 |  |
     	 * タイトルのフォーマット
119 |  |
     	 */
120 | 0 |
     	private MessageFormat	_titleFormat = null;
121 |  |
122 |  |
     	/**
123 |  |
     	 * タイムスタンプのフォーマット
124 |  |
     	 */
125 | 0 |
     	private SimpleDateFormat	_timestampFormat = null;
126 |  |
127 |  |
     	/**
128 |  |
     	 * 未登録セルのタイトル
129 |  |
     	 */
130 | 0 |
     	private String	_nodataTitle = null;
131 |  |
132 |  |
133 |  |
     	/**
134 |  |
     	 * <code>SaveDataInfoRenderer</code> のインスタンスを生成します。
135 |  |
     	 */
136 |  |
     	public SaveDataInfoRenderer()
137 | 0 |
     	{
138 | 0 |
     		ResourceManager	resources = ResourceManager.getInstance();
139 | 0 |
     		ColorManager	colors = ColorManager.getInstance();
140 | 0 |
     		FontManager	fonts = FontManager.getInstance();
141 |  |
142 | 0 |
     		Dimension	size = (Dimension)resources.getResource( ResourceIDs.CELL_SIZE );
143 | 0 |
     		if( size == null )	{
144 | 0 |
     			Logger.warn( MessageIDs.SAV0009W, new Object[]{"380,65"} );
145 | 0 |
     			size = new Dimension( 380, 65 );
146 |  |
     		}
147 | 0 |
     		setPreferredSize( size );
148 | 0 |
     		setSize( size );
149 |  |
150 | 0 |
     		_selectedBackground = (Color)resources.getResource( ResourceIDs.CELL_BACKGROUND_SELECTED );
151 | 0 |
     		if( _selectedBackground == null )	{
152 | 0 |
     			_selectedBackground = colors.getColor( "#FF88FF" );
153 | 0 |
     			Logger.warn( MessageIDs.SAV0024W, new Object[]{"cell.background.selected", "#FF88FF"} );
154 |  |
     		}
155 |  |
156 | 0 |
     		_unselectedBackground = (Color)resources.getResource( ResourceIDs.CELL_BACKGROUND_UNSELECTED );
157 | 0 |
     		if( _unselectedBackground == null )	{
158 | 0 |
     			_unselectedBackground = colors.getColor( "white" );
159 | 0 |
     			Logger.warn( MessageIDs.SAV0024W, new Object[]{"cell.background.unselected", "white"} );
160 |  |
     		}
161 |  |
162 | 0 |
     		_titleColor = (Color)resources.getResource( ResourceIDs.CELL_TITLE_COLOR );
163 | 0 |
     		if( _titleColor == null )	{
164 | 0 |
     			_titleColor = colors.getColor( "black" );
165 | 0 |
     			Logger.warn( MessageIDs.SAV0023W, new Object[]{"cell.title", "black", } );
166 |  |
     		}
167 |  |
168 | 0 |
     		_timestampColor = (Color)resources.getResource( ResourceIDs.CELL_TIMESTAMP_COLOR );
169 | 0 |
     		if( _timestampColor == null )	{
170 | 0 |
     			_timestampColor = colors.getColor( "black" );
171 | 0 |
     			Logger.warn( MessageIDs.SAV0023W, new Object[]{"cell.timestamp", "black"} );
172 |  |
     		}
173 |  |
174 | 0 |
     		_commentColor = (Color)resources.getResource( ResourceIDs.CELL_COMMENT_COLOR );
175 | 0 |
     		if( _commentColor == null )	{
176 | 0 |
     			_commentColor = colors.getColor( "black" );
177 | 0 |
     			Logger.warn( MessageIDs.SAV0023W, new Object[]{"cell.comment", "black"} );
178 |  |
     		}
179 |  |
180 |  |
181 | 0 |
     		_titleFont = (Font)resources.getResource( ResourceIDs.CELL_TITLE_FONT );
182 | 0 |
     		if( _titleFont == null )	{
183 | 0 |
     			Logger.warn( MessageIDs.SAV0010W, new Object[]{"cell.title", "family:SansSerif; size:16.0; style:normal; weight:bold"} );
184 | 0 |
     			Map	attributes = new java.util.HashMap();
185 | 0 |
     			attributes.put( TextAttribute.FAMILY, "SansSerif" );
186 | 0 |
     			attributes.put( TextAttribute.SIZE, new Float(16f) );
187 | 0 |
     			attributes.put( TextAttribute.POSTURE, TextAttribute.POSTURE_REGULAR );
188 | 0 |
     			attributes.put( TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD );
189 | 0 |
     			_titleFont = fonts.getFont( attributes );
190 |  |
     		}
191 |  |
192 | 0 |
     		_timestampFont = (Font)resources.getResource( ResourceIDs.CELL_TIMESTAMP_FONT );
193 | 0 |
     		if( _timestampFont == null )	{
194 | 0 |
     			Logger.warn( MessageIDs.SAV0010W, new Object[]{"cell.timestamp", "family:SansSerif; size:11.0; style:normal; weight:normarl"} );
195 | 0 |
     			Map	attributes = new java.util.HashMap();
196 | 0 |
     			attributes.put( TextAttribute.FAMILY, "SansSerif" );
197 | 0 |
     			attributes.put( TextAttribute.SIZE, new Float(11f) );
198 | 0 |
     			attributes.put( TextAttribute.POSTURE, TextAttribute.POSTURE_REGULAR );
199 | 0 |
     			attributes.put( TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD );
200 | 0 |
     			_timestampFont = fonts.getFont( attributes );
201 |  |
     		}
202 |  |
203 | 0 |
     		_commentFont = (Font)resources.getResource( ResourceIDs.CELL_COMMENT_FONT );
204 | 0 |
     		if( _timestampFont == null )	{
205 | 0 |
     			Logger.warn( MessageIDs.SAV0010W, new Object[]{"cell.comment", "family:SansSerif; size:16.0; style:normal; weight:normarl"} );
206 | 0 |
     			Map	attributes = new java.util.HashMap();
207 | 0 |
     			attributes.put( TextAttribute.FAMILY, "SansSerif" );
208 | 0 |
     			attributes.put( TextAttribute.SIZE, new Float(11f) );
209 | 0 |
     			attributes.put( TextAttribute.POSTURE, TextAttribute.POSTURE_REGULAR );
210 | 0 |
     			attributes.put( TextAttribute.WEIGHT, TextAttribute.WEIGHT_BOLD );
211 | 0 |
     			_commentFont = fonts.getFont( attributes );
212 |  |
     		}
213 |  |
214 | 0 |
     		_titleFormat = (MessageFormat)resources.getResource( ResourceIDs.CELL_TITLE_FORMAT );
215 | 0 |
     		if( _titleFormat == null )	{
216 | 0 |
     			_titleFormat = new MessageFormat( "No.{0}  {1}" );
217 | 0 |
     			Logger.warn( MessageIDs.SAV0011W, new Object[]{"\"No.{0}  {1}\""} );
218 |  |
     		}
219 |  |
220 | 0 |
     		String	timestampFormat = (String)resources.getResource( ResourceIDs.CELL_TIMESTAMP_FORMAT );
221 | 0 |
     		if( timestampFormat == null )	{
222 | 0 |
     			timestampFormat = "yyyy/MM/dd hh:mm";
223 | 0 |
     			Logger.warn( MessageIDs.SAV0017W, new Object[]{"\"" + timestampFormat + "\""} );
224 |  |
     		}
225 | 0 |
     		_timestampFormat = new SimpleDateFormat( timestampFormat );
226 |  |
227 | 0 |
     		_nodataTitle = (String)resources.getResource( ResourceIDs.CELL_NO_DATA_TITLE );
228 | 0 |
     		if( _nodataTitle == null )	{
229 | 0 |
     			_nodataTitle = "-NO DATA-";
230 | 0 |
     			Logger.warn( MessageIDs.SAV0018W, new Object[]{"\"" + _nodataTitle + "\""} );
231 |  |
     		}
232 | 0 |
     	}
233 |  |
234 |  |
235 |  |
     //
236 |  |
     //	JComponent の実装
237 |  |
     //
238 |  |
     	public void paintComponent( Graphics g )
239 |  |
     	{
240 | 0 |
     		Dimension	size = getSize();
241 | 0 |
     		if( _selected )	{
242 | 0 |
     			g.setColor( _selectedBackground );
243 | 0 |
     		}
244 |  |
     		else	{
245 | 0 |
     			g.setColor( _unselectedBackground );
246 |  |
     		}
247 | 0 |
     		g.fillRect( 0, 0, size.width, size.height );
248 |  |
249 | 0 |
     		g.setColor( Color.black );
250 |  |
251 | 0 |
     		Graphics2D	g2 = (Graphics2D)g;
252 | 0 |
     		g2.setRenderingHint( RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON );
253 | 0 |
     		float	y = 3f;
254 | 0 |
     		AttributedString	as = null;
255 | 0 |
     		TextLayout	layout = null;
256 |  |
257 | 0 |
     		if( _info == null )	{
258 | 0 |
     			as = new AttributedString( _titleFormat.format(class="keyword">new Object[]{String.valueOf(_index + 1), _nodataTitle}) );
259 | 0 |
     			as.addAttribute( TextAttribute.FONT, _titleFont );
260 | 0 |
     			as.addAttribute( TextAttribute.FOREGROUND, _titleColor );
261 |  |
262 | 0 |
     			layout = new TextLayout( as.getIterator(), g2.getFontRenderContext() );
263 | 0 |
     			layout.draw( g2, 5, layout.getAscent() + y );
264 | 0 |
     			y += layout.getAscent() + layout.getDescent() + 5f;
265 | 0 |
     		}
266 |  |
     		else	{
267 | 0 |
     			as = new AttributedString( _titleFormat.format(class="keyword">new Object[]{String.valueOf(_index + 1), _info.getTitle()}) );
268 | 0 |
     			as.addAttribute( TextAttribute.FONT, _titleFont );
269 | 0 |
     			as.addAttribute( TextAttribute.FOREGROUND, _titleColor );
270 |  |
271 | 0 |
     			layout = new TextLayout( as.getIterator(), g2.getFontRenderContext() );
272 | 0 |
     			layout.draw( g2, 5, layout.getAscent() + y );
273 | 0 |
     			y += layout.getAscent() + layout.getDescent() + 5f;
274 |  |
275 | 0 |
     			as = new AttributedString( _timestampFormat.format(_info.getTimestamp()) );
276 | 0 |
     			as.addAttribute( TextAttribute.FONT, _timestampFont );
277 | 0 |
     			as.addAttribute( TextAttribute.FOREGROUND, _timestampColor );
278 |  |
279 | 0 |
     			layout = new TextLayout( as.getIterator(), g2.getFontRenderContext() );
280 | 0 |
     			layout.draw( g2, 5, layout.getAscent() + y );
281 | 0 |
     			y += layout.getAscent() + layout.getDescent() + 5f;
282 |  |
283 | 0 |
     			if( _info.getComment() != null )	{
284 | 0 |
     				as = new AttributedString( _info.getComment() );
285 | 0 |
     				as.addAttribute( TextAttribute.FONT, _commentFont );
286 | 0 |
     				as.addAttribute( TextAttribute.FOREGROUND, _commentColor );
287 |  |
288 | 0 |
     				layout = new TextLayout( as.getIterator(), g2.getFontRenderContext() );
289 | 0 |
     				layout.draw( g2, 5, layout.getAscent() + y );
290 |  |
     			}
291 |  |
     		}
292 | 0 |
     	}
293 |  |
294 |  |
295 |  |
     //
296 |  |
     //	ListCellRenderer の実装
297 |  |
     //
298 |  |
     	public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, class="keyword">boolean cellHasForcus )
299 |  |
     	{
300 | 0 |
     		_info = (SaveDataInfo)value;
301 | 0 |
     		_selected = isSelected;
302 | 0 |
     		_index = index;
303 | 0 |
     		setBorder( BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.LOWERED) );
304 | 0 |
     		return this;
305 |  |
     	}
306 |  |
     }

This report is generated by jcoverage, Maven and Maven JCoverage Plugin.