OSDN Git Service

GUIからコンフィグファイルを直接起動できるよう対応
authoryukihane <yukihane.feather@gmail.com>
Fri, 5 Aug 2011 03:55:36 +0000 (12:55 +0900)
committeryukihane <yukihane.feather@gmail.com>
Fri, 5 Aug 2011 11:03:35 +0000 (20:03 +0900)
src/nicobrowser/config/Config.java
src/nicobrowser/gui/config/ConfigFrame.form
src/nicobrowser/gui/config/ConfigFrame.java

index 03dd226..5296b85 100644 (file)
@@ -25,6 +25,7 @@ public final class Config {
 
     private static Log log = LogFactory.getLog(Config.class);
     private static Config instance;
+
     private final PropertiesConfiguration properties;
     private static final String APPLICATION_NAME = "nicobrowser";
     private static final String CONFIG_NAME = APPLICATION_NAME + ".properties";
@@ -310,6 +311,9 @@ public final class Config {
     public static File getFeedUrlFile() {
         return FEEDURL_FILE;
     }
+    public static File getMylistConfigFile() {
+        return MYLIST_CONFIG_FILE;
+    }
 
     public static File getAppHome() {
         return APP_HOME;
index 04c82de..5e49a81 100644 (file)
                   <EmptySpace max="-2" attributes="0"/>
                   <Group type="103" groupAlignment="0" attributes="0">
                       <Group type="102" attributes="0">
-                          <Component id="mylistFileField" pref="331" max="32767" attributes="0"/>
+                          <Component id="mylistFileField" pref="325" max="32767" attributes="0"/>
                           <EmptySpace max="-2" attributes="0"/>
                           <Component id="mylistFileEditButton" min="-2" max="-2" attributes="0"/>
                       </Group>
                       <Group type="102" alignment="0" attributes="0">
-                          <Component id="feedFileField" pref="331" max="32767" attributes="0"/>
+                          <Component id="feedFileField" pref="325" max="32767" attributes="0"/>
                           <EmptySpace max="-2" attributes="0"/>
                           <Component id="feedFileEditButton" min="-2" max="-2" attributes="0"/>
                       </Group>
         </Component>
         <Component class="javax.swing.JTextField" name="mylistFileField">
           <Properties>
-            <Property name="enabled" type="boolean" value="false"/>
+            <Property name="editable" type="boolean" value="false"/>
           </Properties>
         </Component>
         <Component class="javax.swing.JButton" name="feedFileEditButton">
           <Properties>
-            <Property name="text" type="java.lang.String" value="&#x7de8;&#x96c6;"/>
+            <Property name="text" type="java.lang.String" value="&#x7de8;&#x96c6;..."/>
           </Properties>
+          <Events>
+            <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="feedFileEditButtonActionPerformed"/>
+          </Events>
         </Component>
         <Component class="javax.swing.JButton" name="mylistFileEditButton">
           <Properties>
-            <Property name="text" type="java.lang.String" value="&#x7de8;&#x96c6;"/>
+            <Property name="text" type="java.lang.String" value="&#x7de8;&#x96c6;..."/>
           </Properties>
+          <Events>
+            <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="mylistFileEditButtonActionPerformed"/>
+          </Events>
         </Component>
       </SubComponents>
     </Container>
index 183a0d5..62647a7 100644 (file)
@@ -7,6 +7,9 @@
  */
 package nicobrowser.gui.config;
 
+import java.awt.Desktop;
+import java.io.File;
+import java.io.IOException;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import javax.swing.JFileChooser;
@@ -24,6 +27,7 @@ import org.apache.commons.io.FilenameUtils;
  */
 public class ConfigFrame extends javax.swing.JFrame {
 
+    private static final long serialVersionUID = 1L;
     private final Config config;
 
     /** Creates new form ConfigFrame */
@@ -31,6 +35,7 @@ public class ConfigFrame extends javax.swing.JFrame {
         initComponents();
         configFileField.setText(Config.getConfigfile().getAbsolutePath());
         feedFileField.setText(Config.getFeedUrlFile().getAbsolutePath());
+        mylistFileField.setText(Config.getMylistConfigFile().getAbsolutePath());
         config = Config.getInstance();
 
         // ニコニコ動画アカウント
@@ -121,11 +126,21 @@ public class ConfigFrame extends javax.swing.JFrame {
 
         mylistFileLabel.setText("マイリスト");
 
-        mylistFileField.setEnabled(false);
+        mylistFileField.setEditable(false);
 
-        feedFileEditButton.setText("編集");
+        feedFileEditButton.setText("編集...");
+        feedFileEditButton.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
+                feedFileEditButtonActionPerformed(evt);
+            }
+        });
 
-        mylistFileEditButton.setText("編集");
+        mylistFileEditButton.setText("編集...");
+        mylistFileEditButton.addActionListener(new java.awt.event.ActionListener() {
+            public void actionPerformed(java.awt.event.ActionEvent evt) {
+                mylistFileEditButtonActionPerformed(evt);
+            }
+        });
 
         org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
         jPanel1.setLayout(jPanel1Layout);
@@ -139,11 +154,11 @@ public class ConfigFrame extends javax.swing.JFrame {
                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                 .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                     .add(jPanel1Layout.createSequentialGroup()
-                        .add(mylistFileField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 331, Short.MAX_VALUE)
+                        .add(mylistFileField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 325, Short.MAX_VALUE)
                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                         .add(mylistFileEditButton))
                     .add(jPanel1Layout.createSequentialGroup()
-                        .add(feedFileField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 331, Short.MAX_VALUE)
+                        .add(feedFileField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 325, Short.MAX_VALUE)
                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                         .add(feedFileEditButton))
                     .add(configFileField, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 395, Short.MAX_VALUE)))
@@ -424,12 +439,30 @@ public class ConfigFrame extends javax.swing.JFrame {
         try {
             config.updateConfigFile(p);
             JOptionPane.showMessageDialog(this, Config.getConfigfile().getAbsolutePath() + "\nを更新しました");
-        } catch (ConfigurationException ex){
+        } catch (ConfigurationException ex) {
             Logger.getLogger(ConfigFrame.class.getName()).log(Level.SEVERE, null, ex);
             JOptionPane.showMessageDialog(this, "保存に失敗しました", "エラー", JOptionPane.ERROR_MESSAGE);
         }
     }//GEN-LAST:event_savaButtonActionPerformed
 
+    private void feedFileEditButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_feedFileEditButtonActionPerformed
+        editConfigFile(Config.getFeedUrlFile());
+    }//GEN-LAST:event_feedFileEditButtonActionPerformed
+
+    private void mylistFileEditButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mylistFileEditButtonActionPerformed
+        editConfigFile(Config.getMylistConfigFile());
+    }//GEN-LAST:event_mylistFileEditButtonActionPerformed
+
+    private void editConfigFile(File file) {
+        Desktop d = Desktop.getDesktop();
+        try {
+            d.edit(file);
+        } catch (IOException ex) {
+            Logger.getLogger(ConfigFrame.class.getName()).log(Level.SEVERE, null, ex);
+            JOptionPane.showMessageDialog(this, ex.getMessage(), "エラー", JOptionPane.ERROR_MESSAGE);
+        }
+    }
+
     private void setPathField(JTextField field) {
         String current = field.getText();
         JFileChooser fc = new JFileChooser(current);