OSDN Git Service

Merge branch 'release/v4.101.2'
[jindolf/Jindolf.git] / src / main / java / jp / sfjp / jindolf / view / HelpFrame.java
1 /*
2  * help frame
3  *
4  * License : The MIT License
5  * Copyright(c) 2008 olyutorskii
6  */
7
8 package jp.sfjp.jindolf.view;
9
10 import java.awt.Container;
11 import java.awt.GridBagConstraints;
12 import java.awt.GridBagLayout;
13 import java.awt.Insets;
14 import java.awt.event.ActionEvent;
15 import java.awt.event.ActionListener;
16 import java.awt.event.WindowAdapter;
17 import java.awt.event.WindowEvent;
18 import java.io.IOException;
19 import java.net.URL;
20 import java.util.logging.Level;
21 import java.util.logging.Logger;
22 import javax.swing.BorderFactory;
23 import javax.swing.JButton;
24 import javax.swing.JEditorPane;
25 import javax.swing.JFrame;
26 import javax.swing.JScrollPane;
27 import javax.swing.JSeparator;
28 import javax.swing.JTabbedPane;
29 import javax.swing.JTextArea;
30 import javax.swing.border.Border;
31 import javax.swing.event.HyperlinkEvent;
32 import javax.swing.event.HyperlinkListener;
33 import jp.sfjp.jindolf.ResourceManager;
34 import jp.sfjp.jindolf.config.ConfigStore;
35 import jp.sfjp.jindolf.config.EnvInfo;
36 import jp.sfjp.jindolf.config.OptionInfo;
37 import jp.sfjp.jindolf.dxchg.TextPopup;
38 import jp.sfjp.jindolf.util.GUIUtils;
39
40 /**
41  * ヘルプ画面。
42  */
43 @SuppressWarnings("serial")
44 public class HelpFrame extends JFrame
45         implements ActionListener, HyperlinkListener{
46
47     private static final String HELP_HTML = "resources/html/help.html";
48
49     private static final Logger LOGGER = Logger.getAnonymousLogger();
50
51
52     private final JTabbedPane tabPanel = new JTabbedPane();
53     private final JEditorPane htmlView = new JEditorPane();
54     private final JTextArea vmInfo = new JTextArea();
55     private final JButton closeButton = new JButton("閉じる");
56
57     /**
58      * コンストラクタ。
59      */
60     @SuppressWarnings("LeakingThisInConstructor")
61     public HelpFrame(){
62         super();
63
64         GUIUtils.modifyWindowAttributes(this, true, false, true);
65
66         this.htmlView.setEditable(false);
67         this.htmlView.setContentType("text/html");
68         this.htmlView.putClientProperty(JEditorPane.W3C_LENGTH_UNITS,
69                                         Boolean.TRUE);
70         this.htmlView.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES,
71                                         Boolean.TRUE);
72         Border border = BorderFactory.createEmptyBorder(0, 0, 0, 0);
73         this.htmlView.setBorder(border);
74         this.htmlView.addHyperlinkListener(this);
75         this.htmlView.setComponentPopupMenu(new TextPopup());
76
77         this.vmInfo.setEditable(false);
78         this.vmInfo.setLineWrap(true);
79         this.vmInfo.setComponentPopupMenu(new TextPopup());
80
81         this.closeButton.addActionListener(this);
82
83         setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
84         addWindowListener(new WindowAdapter(){
85             @Override
86             public void windowClosing(WindowEvent event){
87                 close();
88             }
89         });
90
91         URL topUrl = ResourceManager.getResource(HELP_HTML);
92         loadURL(topUrl);
93
94         design();
95
96         return;
97     }
98
99     /**
100      * デザインを行う。
101      */
102     private void design(){
103         Container content = this.getContentPane();
104         GridBagLayout layout = new GridBagLayout();
105         GridBagConstraints constraints = new GridBagConstraints();
106         content.setLayout(layout);
107
108         constraints.gridwidth = GridBagConstraints.REMAINDER;
109         constraints.insets = new Insets(5, 5, 5, 5);
110         constraints.weightx = 1.0;
111         constraints.weighty = 1.0;
112         constraints.fill = GridBagConstraints.BOTH;
113
114         JScrollPane sc = new JScrollPane(this.htmlView);
115         this.tabPanel.add("ヘルプ", sc);
116         sc = new JScrollPane(this.vmInfo);
117         this.tabPanel.add("実行環境", sc);
118         content.add(this.tabPanel, constraints);
119
120         constraints.weighty = 0.0;
121         constraints.fill = GridBagConstraints.HORIZONTAL;
122         content.add(new JSeparator(), constraints);
123
124         constraints.weightx = 0.0;
125         constraints.anchor = GridBagConstraints.EAST;
126         constraints.fill = GridBagConstraints.NONE;
127         content.add(this.closeButton, constraints);
128
129         return;
130     }
131
132     /**
133      * ウィンドウを閉じる。
134      */
135     private void close(){
136         setVisible(false);
137         return;
138     }
139
140     /**
141      * URLの示すHTML文書を表示する。
142      * @param url URL
143      */
144     private void loadURL(URL url){
145         if(url == null) return;
146
147         try{
148             this.htmlView.setPage(url);
149         }catch(IOException e){
150             LOGGER.log(Level.WARNING, "ヘルプファイルが読み込めません", e);
151             assert false;
152         }
153
154         return;
155     }
156
157     /**
158      * 実行環境に関する情報を更新する。
159      * @param optinfo コマンドライン引数情報
160      * @param configStore 設定ファイル情報
161      */
162     public void updateVmInfo(OptionInfo optinfo, ConfigStore configStore){
163         StringBuilder info = new StringBuilder();
164
165         info.append("起動時引数:\n");
166         for(String arg : optinfo.getInvokeArgList()){
167             info.append("\u0020\u0020").append(arg).append('\n');
168         }
169         info.append('\n');
170
171         info.append(EnvInfo.getVMInfo());
172
173         if(configStore.useStoreFile()){
174             info.append("設定格納ディレクトリ : ")
175                 .append(configStore.getConfigDir().getPath());
176         }else{
177             info.append("※ 設定格納ディレクトリは使っていません。");
178         }
179
180         this.vmInfo.setText(info.toString());
181
182         return;
183     }
184
185     /**
186      * {@inheritDoc}
187      * 閉じるボタン押下処理。
188      * @param event ボタン押下イベント {@inheritDoc}
189      */
190     @Override
191     public void actionPerformed(ActionEvent event){
192         if(event.getSource() != this.closeButton) return;
193         close();
194         return;
195     }
196
197     /**
198      * {@inheritDoc}
199      * リンククリック処理。
200      * @param event リンククリックイベント {@inheritDoc}
201      */
202     @Override
203     public void hyperlinkUpdate(HyperlinkEvent event){
204         if(event.getEventType() != HyperlinkEvent.EventType.ACTIVATED){
205             return;
206         }
207
208         URL url = event.getURL();
209         loadURL(url);
210
211         return;
212     }
213
214 }