4 * License : The MIT License
5 * Copyright(c) 2008 olyutorskii
8 package jp.sfjp.jindolf.glyph;
10 import java.awt.Color;
11 import java.awt.Graphics2D;
12 import java.awt.Point;
13 import java.awt.Rectangle;
14 import java.awt.RenderingHints;
15 import java.io.IOException;
16 import jp.osdn.jindolf.parser.content.DecodedContent;
17 import jp.sfjp.jindolf.data.DialogPref;
18 import jp.sfjp.jindolf.data.SysEvent;
23 public class SysEventDraw extends AbstractTextRow{
25 /** announceメッセージの色。 */
26 public static final Color COLOR_ANNOUNCE = new Color(0xffffff);
28 public static final Color COLOR_ORDER = new Color(0xf04040);
30 public static final Color COLOR_EXTRA = new Color(0x808080);
32 private static final Color COLOR_SIMPLEFG = Color.BLACK;
34 private static final int INSET = 10;
35 private static final int UNDER_MARGIN = 15;
37 private final SysEvent sysEvent;
38 private final GlyphDraw sysMessage;
40 private DialogPref dialogPref;
41 private Color fgColor;
45 * @param sysEvent システムイベント
47 public SysEventDraw(SysEvent sysEvent){
48 this(sysEvent, new DialogPref(), FontInfo.DEFAULT_FONTINFO);
54 * @param sysEvent システムイベント
56 * @param fontInfo フォント設定
58 public SysEventDraw(SysEvent sysEvent,
62 this.sysEvent = sysEvent;
64 DecodedContent content = this.sysEvent.getContent();
65 CharSequence rawContent = content.getRawContent();
67 this.sysMessage = new GlyphDraw(rawContent, this.fontInfo);
69 this.dialogPref = pref;
79 private void setColorDesign(){
80 if(this.dialogPref.isSimpleMode()){
81 this.fgColor = COLOR_SIMPLEFG;
83 this.fgColor = getEventColor();
86 this.sysMessage.setColor(this.fgColor);
95 public SysEvent getSysEvent(){
103 private Color getEventColor(){
105 switch(this.sysEvent.getEventFamily()){
107 result = COLOR_ANNOUNCE;
110 result = COLOR_ORDER;
113 result = COLOR_EXTRA;
124 * @return {@inheritDoc}
127 public Rectangle recalcBounds(){
128 int newWidth = getWidth();
131 child = this.sysMessage.setWidth(newWidth - INSET - INSET);
132 this.bounds.width = newWidth;
133 this.bounds.height = child.height + INSET + INSET + UNDER_MARGIN;
139 * @param fontInfo {@inheritDoc}
142 public void setFontInfo(FontInfo fontInfo){
143 super.setFontInfo(fontInfo);
144 this.sysMessage.setFontInfo(this.fontInfo);
153 public void setDialogPref(DialogPref pref){
154 this.dialogPref = pref;
164 * @param from {@inheritDoc}
165 * @param to {@inheritDoc}
168 public void drag(Point from, Point to){
169 this.sysMessage.drag(from, to);
175 * @param appendable {@inheritDoc}
176 * @return {@inheritDoc}
177 * @throws java.io.IOException {@inheritDoc}
180 public Appendable appendSelected(Appendable appendable)
182 this.sysMessage.appendSelected(appendable);
190 public void clearSelect(){
191 this.sysMessage.clearSelect();
197 * @param xPos {@inheritDoc}
198 * @param yPos {@inheritDoc}
201 public void setPos(int xPos, int yPos){
202 super.setPos(xPos, yPos);
203 this.sysMessage.setPos(this.bounds.x + INSET, this.bounds.y + INSET);
209 * @param g {@inheritDoc}
212 public void paint(Graphics2D g){
213 g.setColor(this.fgColor);
215 RenderingHints.Key aaHintKey = RenderingHints.KEY_ANTIALIASING;
216 Object aaHintTemp = RenderingHints.VALUE_ANTIALIAS_OFF;
217 Object aaHintOrig = g.getRenderingHint(aaHintKey);
219 RenderingHints.Key strokeHintKey = RenderingHints.KEY_STROKE_CONTROL;
220 Object strokeHintTemp = RenderingHints.VALUE_STROKE_NORMALIZE;
221 Object strokeHintOrig = g.getRenderingHint(strokeHintKey);
223 g.setRenderingHint(aaHintKey, aaHintTemp);
224 g.setRenderingHint(strokeHintKey, strokeHintTemp);
226 if(this.dialogPref.isSimpleMode()){
227 g.drawLine(this.bounds.x, this.bounds.y,
228 this.bounds.x + this.bounds.width, this.bounds.y );
230 g.drawRect(this.bounds.x,
232 this.bounds.width - 1,
233 this.bounds.height - UNDER_MARGIN);
236 g.setRenderingHint(aaHintKey, aaHintOrig);
237 g.setRenderingHint(strokeHintKey, strokeHintOrig);
239 this.sysMessage.paint(g);