OSDN Git Service

リファクタリング
[coroid/inqubus.git] / frontend / src / yukihane / inqubus / Main.java
1 package yukihane.inqubus;
2
3 import yukihane.inqubus.config.Config;
4 import java.nio.file.Path;
5 import java.nio.file.Paths;
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 Path path = Paths.get("inqubus.xml");
25         boolean showWelcome;
26         try {
27             Config.INSTANCE.load(path.toString());
28             showWelcome = false;
29         } catch (ConfigurationException ex) {
30             showWelcome = true;
31             logger.log(Level.FINER, "コンフィグファイルが無いためデフォルト値で起動", ex);
32         }
33         final RunWindow invoke = new RunWindow(showWelcome);
34         java.awt.EventQueue.invokeLater(invoke);
35     }
36
37     private static class RunWindow implements Runnable {
38         private final boolean showWelcome;
39         private RunWindow(boolean showWelcome) {
40             this.showWelcome = showWelcome;
41         }
42
43         @Override
44         public void run() {
45             setLookAndFeel();
46             final MainFrame frame = new MainFrame();
47             frame.startWatcher();
48             frame.setVisible(true);
49             if(showWelcome) {
50                 JOptionPane.showMessageDialog(frame, "<html>設定はメニューの <b>ツール > オプション</b> から行えます</html>", "いんきゅばすへようこそ", JOptionPane.INFORMATION_MESSAGE);
51             }
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 }