4 * License : The MIT License
5 * Copyright(c) 2008 olyutorskii
8 package jp.sfjp.jindolf.view;
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;
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;
43 @SuppressWarnings("serial")
44 public class HelpFrame extends JFrame
45 implements ActionListener, HyperlinkListener{
47 private static final String HELP_HTML = "resources/html/help.html";
49 private static final Logger LOGGER = Logger.getAnonymousLogger();
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("閉じる");
60 @SuppressWarnings("LeakingThisInConstructor")
64 GUIUtils.modifyWindowAttributes(this, true, false, true);
66 this.htmlView.setEditable(false);
67 this.htmlView.setContentType("text/html");
68 this.htmlView.putClientProperty(JEditorPane.W3C_LENGTH_UNITS,
70 this.htmlView.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES,
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());
77 this.vmInfo.setEditable(false);
78 this.vmInfo.setLineWrap(true);
79 this.vmInfo.setComponentPopupMenu(new TextPopup());
81 this.closeButton.addActionListener(this);
83 setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
84 addWindowListener(new WindowAdapter(){
86 public void windowClosing(WindowEvent event){
91 URL topUrl = ResourceManager.getResource(HELP_HTML);
102 private void design(){
103 Container content = this.getContentPane();
104 GridBagLayout layout = new GridBagLayout();
105 GridBagConstraints constraints = new GridBagConstraints();
106 content.setLayout(layout);
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;
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);
120 constraints.weighty = 0.0;
121 constraints.fill = GridBagConstraints.HORIZONTAL;
122 content.add(new JSeparator(), constraints);
124 constraints.weightx = 0.0;
125 constraints.anchor = GridBagConstraints.EAST;
126 constraints.fill = GridBagConstraints.NONE;
127 content.add(this.closeButton, constraints);
135 private void close(){
144 private void loadURL(URL url){
145 if(url == null) return;
148 this.htmlView.setPage(url);
149 }catch(IOException e){
150 LOGGER.log(Level.WARNING, "ヘルプファイルが読み込めません", e);
159 * @param optinfo コマンドライン引数情報
160 * @param configStore 設定ファイル情報
162 public void updateVmInfo(OptionInfo optinfo, ConfigStore configStore){
163 StringBuilder info = new StringBuilder();
165 info.append("起動時引数:\n");
166 for(String arg : optinfo.getInvokeArgList()){
167 info.append("\u0020\u0020").append(arg).append('\n');
171 info.append(EnvInfo.getVMInfo());
173 if(configStore.useStoreFile()){
174 info.append("設定格納ディレクトリ : ")
175 .append(configStore.getConfigDir().getPath());
177 info.append("※ 設定格納ディレクトリは使っていません。");
180 this.vmInfo.setText(info.toString());
188 * @param event ボタン押下イベント {@inheritDoc}
191 public void actionPerformed(ActionEvent event){
192 if(event.getSource() != this.closeButton) return;
200 * @param event リンククリックイベント {@inheritDoc}
203 public void hyperlinkUpdate(HyperlinkEvent event){
204 if(event.getEventType() != HyperlinkEvent.EventType.ACTIVATED){
208 URL url = event.getURL();