OSDN Git Service

cee2da9c47e1bb422f738a259c08519f978f792a
[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
39         private final boolean showWelcome;
40
41         private RunWindow(boolean showWelcome) {
42             this.showWelcome = showWelcome;
43         }
44
45         @Override
46         public void run() {
47             setLookAndFeel();
48             final MainFrame frame = new MainFrame();
49             frame.startWatcher();
50             frame.setVisible(true);
51             if (showWelcome) {
52                 JOptionPane.showMessageDialog(frame,
53                         "<html>設定はメニューの <b>ツール > オプション</b> から行えます</html>",
54                         "いんきゅばすへようこそ", JOptionPane.INFORMATION_MESSAGE);
55             }
56         }
57     }
58
59     private static void setLookAndFeel() {
60         try {
61             for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
62                 if ("Nimbus".equals(info.getName())) {
63                     UIManager.setLookAndFeel(info.getClassName());
64                     break;
65                 }
66             }
67         } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) {
68             try {
69                 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
70             } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
71                 // System Look & Feel も無いことは無いだろう
72             }
73         }
74     }
75 }