OSDN Git Service

8c039b409c20ffebd02127fc0aab38b84f7f596a
[jindolf/Jindolf.git] / src / main / java / jp / sfjp / jindolf / view / LandInfoPanel.java
1 /*
2  * Land information panel
3  *
4  * License : The MIT License
5  * Copyright(c) 2009 olyutorskii
6  */
7
8 package jp.sfjp.jindolf.view;
9
10 import java.awt.GridBagConstraints;
11 import java.awt.GridBagLayout;
12 import java.awt.Insets;
13 import java.text.DateFormat;
14 import java.util.Date;
15 import javax.swing.JComponent;
16 import javax.swing.JLabel;
17 import javax.swing.JPanel;
18 import jp.sfjp.jindolf.data.Land;
19 import jp.sfjp.jindolf.dxchg.WebButton;
20 import jp.sfjp.jindolf.util.Monodizer;
21 import jp.sourceforge.jindolf.corelib.LandDef;
22 import jp.sourceforge.jindolf.corelib.LandState;
23
24 /**
25  * 国情報表示パネル。
26  */
27 @SuppressWarnings("serial")
28 public class LandInfoPanel extends JPanel{
29
30     private final JLabel landName       = new JLabel();
31     private final JLabel landIdentifier = new JLabel();
32     private final WebButton webURL      = new WebButton();
33     private final JLabel startDate      = new JLabel();
34     private final JLabel endDate        = new JLabel();
35     private final JLabel landState      = new JLabel();
36     private final JLabel locale         = new JLabel();
37     private final JLabel timezone       = new JLabel();
38     private final WebButton contact     = new WebButton();
39     private final JLabel description    = new JLabel();
40
41
42     /**
43      * コンストラクタ。
44      */
45     public LandInfoPanel(){
46         super();
47
48         Monodizer.monodize(this.landIdentifier);
49         Monodizer.monodize(this.locale);
50
51         design();
52
53         return;
54     }
55
56
57     /**
58      * 国の状態を文字列化する。
59      * @param state 国状態
60      * @return 文字列化された国状態
61      */
62     private static String getStatusMark(LandState state){
63         String result;
64
65         switch(state){
66         case CLOSED:     result = "サービス終了";     break;
67         case HISTORICAL: result = "過去ログ提供のみ"; break;
68         case ACTIVE:     result = "稼動中";           break;
69         default:
70             assert false;
71             result = "";
72             break;
73         }
74
75         return result;
76     }
77
78     /**
79      * 一行分レイアウトする。
80      * @param item 項目名
81      * @param comp コンポーネント
82      */
83     private void layoutRow(String item, JComponent comp){
84         GridBagConstraints constraints = new GridBagConstraints();
85         constraints.insets = new Insets(2, 2, 2, 2);
86
87         String itemCaption = item + " : ";
88         JLabel itemLabel = new JLabel(itemCaption);
89
90         constraints.anchor = GridBagConstraints.EAST;
91         constraints.gridwidth = 1;
92         add(itemLabel, constraints);
93
94         constraints.anchor = GridBagConstraints.WEST;
95         constraints.gridwidth = GridBagConstraints.REMAINDER;
96         add(comp, constraints);
97
98     }
99
100     /**
101      * レイアウトを行う。
102      */
103     private void design(){
104         GridBagLayout layout = new GridBagLayout();
105         setLayout(layout);
106
107         layoutRow("国名",      this.landName);
108         layoutRow("識別名",    this.landIdentifier);
109         layoutRow("Webサイト", this.webURL);
110         layoutRow("建国",      this.startDate);
111         layoutRow("亡国",      this.endDate);
112         layoutRow("状態",      this.landState);
113         layoutRow("ロケール",  this.locale);
114         layoutRow("時間帯",    this.timezone);
115         layoutRow("連絡先",    this.contact);
116         layoutRow("説明",      this.description);
117
118         GridBagConstraints constraints = new GridBagConstraints();
119         constraints.fill = GridBagConstraints.BOTH;
120         constraints.weightx = 1.0;
121         constraints.weighty = 1.0;
122         constraints.gridwidth = GridBagConstraints.REMAINDER;
123         constraints.gridheight = GridBagConstraints.REMAINDER;
124         add(new JPanel(), constraints);  // ダミー詰め物
125
126         return;
127     }
128
129     /**
130      * 国情報を更新する。
131      * @param land 国
132      */
133     public void update(Land land){
134         LandDef landDef = land.getLandDef();
135
136         DateFormat dform =
137             DateFormat.getDateTimeInstance(DateFormat.FULL,
138                                            DateFormat.FULL);
139
140         long start = landDef.getStartDateTime();
141         String startStr = dform.format(new Date(start));
142         if(start < 0){
143             startStr = "(不明)";
144         }
145
146         long end   = landDef.getEndDateTime();
147         String endStr = dform.format(new Date(end));
148         if(end < 0){
149             endStr = "まだまだ";
150         }
151
152         String status = getStatusMark(land.getLandDef().getLandState());
153
154         this.landName       .setText(landDef.getLandName());
155         this.landIdentifier .setText(landDef.getLandId());
156         this.webURL         .setURI(land.getLandDef().getWebURI());
157         this.startDate      .setText(startStr);
158         this.endDate        .setText(endStr);
159         this.landState      .setText(status);
160         this.locale         .setText(landDef.getLocale().toString());
161         this.timezone       .setText(landDef.getTimeZone().getDisplayName());
162         this.contact        .setURLText(landDef.getContactInfo());
163         this.description    .setText(landDef.getDescription());
164
165         revalidate();
166
167         return;
168     }
169
170 }