OSDN Git Service

メニューバー実装
[coroid/inqubus.git] / frontend / src / yukihane / inqubus / gui / MainFrame.java
index eeb464e..409d124 100644 (file)
@@ -5,12 +5,19 @@
  */
 package yukihane.inqubus.gui;
 
+import java.awt.Image;
 import java.awt.ItemSelectable;
+import java.awt.Toolkit;
 import java.awt.datatransfer.DataFlavor;
 import java.awt.datatransfer.Transferable;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
 import java.awt.event.ItemEvent;
+import java.awt.event.KeyEvent;
 import java.io.File;
 import java.io.FilenameFilter;
+import java.net.URL;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 import java.util.logging.Level;
@@ -18,10 +25,13 @@ import java.util.logging.Logger;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import javax.swing.JButton;
+import javax.swing.JMenu;
+import javax.swing.JMenuBar;
+import javax.swing.JMenuItem;
 import javax.swing.JTextField;
+import javax.swing.KeyStroke;
 import javax.swing.TransferHandler;
-import javax.swing.UIManager;
-import javax.swing.UIManager.LookAndFeelInfo;
+import saccubus.MainFrame_AboutBox;
 import yukihane.inqubus.config.Properties;
 import yukihane.inqubus.model.Target;
 import yukihane.inqubus.model.TargetsTableModel;
@@ -52,6 +62,14 @@ public class MainFrame extends javax.swing.JFrame {
     @SuppressWarnings("unchecked")
     // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
     private void initComponents() {
+        final URL url = MainFrame_AboutBox.class.getResource("icon.png");
+        final Image icon1 = Toolkit.getDefaultToolkit().createImage(url);
+        final URL url32 = MainFrame_AboutBox.class.getResource("icon32.png");
+        final Image icon2 = Toolkit.getDefaultToolkit().createImage(url32);
+        final List<Image> images = new ArrayList<Image>(2);
+        images.add(icon1);
+        images.add(icon2);
+        setIconImages(images);
 
         jPanel1 = new javax.swing.JPanel();
         jScrollPane1 = new javax.swing.JScrollPane();
@@ -75,9 +93,6 @@ public class MainFrame extends javax.swing.JFrame {
         outputConvertCheckBox = new javax.swing.JCheckBox();
         outputFileField = new javax.swing.JTextField();
         applyButton = new javax.swing.JButton();
-        jMenuBar1 = new javax.swing.JMenuBar();
-        jMenu1 = new javax.swing.JMenu();
-        jMenu2 = new javax.swing.JMenu();
 
         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
 
@@ -124,6 +139,7 @@ public class MainFrame extends javax.swing.JFrame {
         idLabel.setText("ID");
 
         idField.addFocusListener(new java.awt.event.FocusAdapter() {
+
             public void focusLost(java.awt.event.FocusEvent evt) {
                 idFieldFocusLost(evt);
             }
@@ -133,6 +149,7 @@ public class MainFrame extends javax.swing.JFrame {
 
         useMovieLocalCheckBox.setText("local");
         useMovieLocalCheckBox.addItemListener(new java.awt.event.ItemListener() {
+
             public void itemStateChanged(java.awt.event.ItemEvent evt) {
                 useMovieLocalCheckBoxItemStateChanged(evt);
             }
@@ -144,6 +161,7 @@ public class MainFrame extends javax.swing.JFrame {
 
         useCommentLocalCheckBox.setText("local");
         useCommentLocalCheckBox.addItemListener(new java.awt.event.ItemListener() {
+
             public void itemStateChanged(java.awt.event.ItemEvent evt) {
                 useMovieLocalCheckBoxItemStateChanged(evt);
             }
@@ -155,6 +173,7 @@ public class MainFrame extends javax.swing.JFrame {
 
         outputConvertCheckBox.setText("変換");
         outputConvertCheckBox.addItemListener(new java.awt.event.ItemListener() {
+
             public void itemStateChanged(java.awt.event.ItemEvent evt) {
                 outputConvertCheckBoxItemStateChanged(evt);
             }
@@ -252,13 +271,9 @@ public class MainFrame extends javax.swing.JFrame {
                 .addGap(24, 24, 24))
         );
 
-        jMenu1.setText("File");
-        jMenuBar1.add(jMenu1);
 
-        jMenu2.setText("Edit");
-        jMenuBar1.add(jMenu2);
-
-        setJMenuBar(jMenuBar1);
+        JMenuBar menuBar = initMenuBar();
+        setJMenuBar(menuBar);
 
         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
         getContentPane().setLayout(layout);
@@ -299,95 +314,70 @@ public class MainFrame extends javax.swing.JFrame {
         }
     }
 
-private void useMovieLocalCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_useMovieLocalCheckBoxItemStateChanged
-    final Properties p = Properties.INSTANCE;
-
-    final ItemSelectable source = evt.getItemSelectable();
-
-    JButton btn;
-    JTextField field;
-    File dir;
-    if (source == useMovieLocalCheckBox) {
-        btn = movieFileSelectButton;
-        field = movieFileField;
-        dir = new File(p.getVideoDir());
-    } else {
-        btn = commentFileSelectButton;
-        field = commentFileField;
-        dir = new File(p.getCommentDir());
-    }
+    private void useMovieLocalCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_useMovieLocalCheckBoxItemStateChanged
+        final Properties p = Properties.INSTANCE;
 
-    final boolean useLocal = (evt.getStateChange() == ItemEvent.SELECTED);
-    btn.setEnabled(useLocal);
+        final ItemSelectable source = evt.getItemSelectable();
 
-    String text;
-    if (useLocal) {
-        final File f = searchFileMatchId(dir, idField.getText());
-        if (f != null) {
-            text = f.getPath();
+        JButton btn;
+        JTextField field;
+        File dir;
+        if (source == useMovieLocalCheckBox) {
+            btn = movieFileSelectButton;
+            field = movieFileField;
+            dir = new File(p.getVideoDir());
         } else {
-            text = "";
+            btn = commentFileSelectButton;
+            field = commentFileField;
+            dir = new File(p.getCommentDir());
         }
-    } else {
-        text = p.getVideoFileNamePattern();
-    }
-    field.setText(text);
-}//GEN-LAST:event_useMovieLocalCheckBoxItemStateChanged
-
-private void outputConvertCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_outputConvertCheckBoxItemStateChanged
-    final boolean convert = (evt.getStateChange() == ItemEvent.SELECTED);
-    outputFileField.setEnabled(convert);
-}//GEN-LAST:event_outputConvertCheckBoxItemStateChanged
-
-private void idFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_idFieldFocusLost
-    final Properties p = Properties.INSTANCE;
-    final String id = idField.getText();
-    if (id.isEmpty()) {
-        return;
-    }
 
-    if (useMovieLocalCheckBox.isSelected() && movieFileField.getText().isEmpty()) {
-        final File dir = new File(p.getVideoDir());
-        final File file = searchFileMatchId(dir, id);
-        if (file != null) {
-            movieFileField.setText(file.getPath());
-        }
-    }
+        final boolean useLocal = (evt.getStateChange() == ItemEvent.SELECTED);
+        btn.setEnabled(useLocal);
 
-    if (useCommentLocalCheckBox.isSelected() && commentFileField.getText().isEmpty()) {
-        final File dir = new File(p.getCommentDir());
-        final File file = searchFileMatchId(dir, id);
-        if (file != null) {
-            commentFileField.setText(file.getPath());
+        String text;
+        if (useLocal) {
+            final File f = searchFileMatchId(dir, idField.getText());
+            if (f != null) {
+                text = f.getPath();
+            } else {
+                text = "";
+            }
+        } else {
+            text = p.getVideoFileNamePattern();
         }
-    }
+        field.setText(text);
+    }//GEN-LAST:event_useMovieLocalCheckBoxItemStateChanged
 
-}//GEN-LAST:event_idFieldFocusLost
+    private void outputConvertCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_outputConvertCheckBoxItemStateChanged
+        final boolean convert = (evt.getStateChange() == ItemEvent.SELECTED);
+        outputFileField.setEnabled(convert);
+    }//GEN-LAST:event_outputConvertCheckBoxItemStateChanged
 
-    /**
-     * @param args the command line arguments
-     */
-    public static void main(String args[]) {
-        try {
-            for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
-                if ("Nimbus".equals(info.getName())) {
-                    UIManager.setLookAndFeel(info.getClassName());
-                    break;
-                }
-            }
-        } catch (Exception e) {
-            try {
-                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
-            } catch (Exception ex) {
+    private void idFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_idFieldFocusLost
+        final Properties p = Properties.INSTANCE;
+        final String id = idField.getText();
+        if (id.isEmpty()) {
+            return;
+        }
+
+        if (useMovieLocalCheckBox.isSelected() && movieFileField.getText().isEmpty()) {
+            final File dir = new File(p.getVideoDir());
+            final File file = searchFileMatchId(dir, id);
+            if (file != null) {
+                movieFileField.setText(file.getPath());
             }
         }
-        java.awt.EventQueue.invokeLater(new Runnable() {
 
-            public void run() {
-                new MainFrame().setVisible(true);
+        if (useCommentLocalCheckBox.isSelected() && commentFileField.getText().isEmpty()) {
+            final File dir = new File(p.getCommentDir());
+            final File file = searchFileMatchId(dir, id);
+            if (file != null) {
+                commentFileField.setText(file.getPath());
             }
-        });
-    }
+        }
+
+    }//GEN-LAST:event_idFieldFocusLost
     // Variables declaration - do not modify//GEN-BEGIN:variables
     private javax.swing.JButton applyButton;
     private javax.swing.JTextField commentFileField;
@@ -398,9 +388,6 @@ private void idFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_
     private javax.swing.JButton jButton2;
     private javax.swing.JButton jButton3;
     private javax.swing.JButton jButton4;
-    private javax.swing.JMenu jMenu1;
-    private javax.swing.JMenu jMenu2;
-    private javax.swing.JMenuBar jMenuBar1;
     private javax.swing.JPanel jPanel1;
     private javax.swing.JPanel jPanel2;
     private javax.swing.JPanel jPanel3;
@@ -442,6 +429,60 @@ private void idFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_
 
     }
 
+    private JMenuBar initMenuBar() {
+        final JMenuBar menuBar = new JMenuBar();
+
+        final JMenu mnFile = new JMenu("ファイル(F)");
+        menuBar.add(mnFile);
+
+        final JMenuItem itExit = new JMenuItem("終了(X)", KeyEvent.VK_X);
+        itExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
+        itExit.addActionListener(new ActionListener() {
+
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                throw new UnsupportedOperationException("Not supported yet.");
+            }
+        });
+        mnFile.add(itExit);
+
+        final JMenu mnTool = new JMenu("ツール(T)");
+        menuBar.add(mnTool);
+
+        final JMenuItem itOption = new JMenuItem("オプション(O)...", KeyEvent.VK_O);
+        // TODO ショートカットキー
+        itOption.addActionListener(new ActionListener() {
+
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                final yukihane.inqubus.gui.Properties dlg = new yukihane.inqubus.gui.Properties(MainFrame.this);
+                dlg.setLocationRelativeTo(MainFrame.this);
+                dlg.setModal(true);
+                dlg.setVisible(true);
+            }
+        });
+        mnTool.add(itOption);
+
+        final JMenu mnHelp = new JMenu("ヘルプ(H)");
+        menuBar.add(mnHelp);
+
+        final JMenuItem itAbout = new JMenuItem("このソフトウェアについて(A)...", KeyEvent.VK_A);
+        itAbout.addActionListener(new ActionListener() {
+
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                MainFrame_AboutBox dlg = new MainFrame_AboutBox(MainFrame.this);
+                dlg.pack();
+                dlg.setLocationRelativeTo(MainFrame.this);
+                dlg.setModal(true);
+                dlg.setVisible(true);
+            }
+        });
+        mnHelp.add(itAbout);
+
+        return menuBar;
+    }
+
     private class DownloadListTransferHandler extends TransferHandler {
 
         private static final long serialVersionUID = 1L;
@@ -487,6 +528,7 @@ private void idFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_
     }
 
     private class TableTransferHandler extends DownloadListTransferHandler {
+
         private static final long serialVersionUID = 1L;
 
         @Override