OSDN Git Service

初回起動時(コンフィグファイルが無い場合)にはウェルカムメッセージを表示する
[coroid/inqubus.git] / frontend / src / yukihane / inqubus / Main.java
1 package yukihane.inqubus;
2
3 import java.nio.file.FileSystem;
4 import java.nio.file.FileSystems;
5 import java.nio.file.Path;
6 import java.util.logging.Level;
7 import java.util.logging.Logger;
8 import javax.swing.JOptionPane;
9 import javax.swing.UIManager;
10 import javax.swing.UIManager.LookAndFeelInfo;
11 import javax.swing.UnsupportedLookAndFeelException;
12 import org.apache.commons.configuration.ConfigurationException;
13 import yukihane.inqubus.gui.MainFrame;
14
15 /**
16  * いんきゅばす起動クラス.
17  * @author yuki
18  */
19 public class Main {
20
21     private static final Logger logger = Logger.getLogger(Main.class.getName());
22
23     public static void main(String args[]) {
24         final FileSystem fileSystem = FileSystems.getDefault();
25         final Path path = fileSystem.getPath("inqubus.xml");
26         boolean showWelcome;
27         try {
28             Config.INSTANCE.load(path.toString());
29             showWelcome = false;
30         } catch (ConfigurationException ex) {
31             showWelcome = true;
32             logger.log(Level.FINER, "コンフィグファイルが無いためデフォルト値で起動", ex);
33         }
34         final RunWindow invoke = new RunWindow(showWelcome);
35         java.awt.EventQueue.invokeLater(invoke);
36     }
37
38     private static class RunWindow implements Runnable {
39         private final boolean showWelcome;
40         private RunWindow(boolean showWelcome) {
41             this.showWelcome = showWelcome;
42         }
43
44         @Override
45         public void run() {
46             setLookAndFeel();
47             final MainFrame frame = new MainFrame();
48             if(showWelcome) {
49                 JOptionPane.showMessageDialog(null, "<html>設定はメニューの <b>ツール > オプション</b> から行えます</html>", "いんきゅばすへようこそ", JOptionPane.INFORMATION_MESSAGE);
50             }
51             frame.setVisible(true);
52         }
53     }
54
55     private static void setLookAndFeel() {
56         try {
57             for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
58                 if ("Nimbus".equals(info.getName())) {
59                     UIManager.setLookAndFeel(info.getClassName());
60                     break;
61                 }
62             }
63         } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) {
64             try {
65                 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
66             } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
67                 // System Look & Feel も無いことは無いだろう
68             }
69         }
70     }
71 }