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