OSDN Git Service

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