OSDN Git Service

git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/filelock/trunk@6 c6214a2a-ec3a-0410...
authoruguu <uguu@c6214a2a-ec3a-0410-ae48-a6ea9e4e51c8>
Sun, 30 Sep 2007 18:24:35 +0000 (18:24 +0000)
committeruguu <uguu@c6214a2a-ec3a-0410-ae48-a6ea9e4e51c8>
Sun, 30 Sep 2007 18:24:35 +0000 (18:24 +0000)
filelock/.classpath
filelock/pom.xml
filelock/src/main/java/jp/sourceforge/filelock/AppInfo.java [new file with mode: 0644]
filelock/src/main/java/jp/sourceforge/filelock/ConsoleMain.java
filelock/src/main/java/jp/sourceforge/filelock/SwingMain.java
filelock/src/main/resources/filelock.properties [new file with mode: 0644]

index 1e6d54b..06355fc 100644 (file)
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="UTF-8"?>\r
 <classpath>\r
        <classpathentry kind="src" path="src/main/java"/>\r
+       <classpathentry kind="src" path="src/main/resources"/>\r
        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>\r
        <classpathentry kind="output" path="bin"/>\r
 </classpath>\r
index 1aecd11..925d919 100644 (file)
@@ -68,7 +68,7 @@
                 <configuration>\r
                     <archive>\r
                         <manifest>\r
-                            <mainClass>jp.sourceforge.filelock.ConsoleMain</mainClass>\r
+                            <mainClass>jp.sourceforge.filelock.SwingMain</mainClass>\r
                         </manifest>\r
                     </archive>\r
                 </configuration>\r
diff --git a/filelock/src/main/java/jp/sourceforge/filelock/AppInfo.java b/filelock/src/main/java/jp/sourceforge/filelock/AppInfo.java
new file mode 100644 (file)
index 0000000..6c58994
--- /dev/null
@@ -0,0 +1,112 @@
+/*\r
+ * Copyright (C) 2007 uguu at users.sourceforge.jp, All Rights Reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without\r
+ * modification, are permitted provided that the following conditions\r
+ * are met:\r
+ *\r
+ *    1. Redistributions of source code must retain the above copyright\r
+ *       notice, this list of conditions and the following disclaimer.\r
+ *\r
+ *    2. Redistributions in binary form must reproduce the above copyright\r
+ *       notice, this list of conditions and the following disclaimer in the\r
+ *       documentation and/or other materials provided with the distribution.\r
+ *\r
+ *    3. Neither the name of Clarkware Consulting, Inc. nor the names of its\r
+ *       contributors may be used to endorse or promote products derived\r
+ *       from this software without prior written permission. For written\r
+ *       permission, please contact clarkware@clarkware.com.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,\r
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND\r
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL\r
+ * CLARKWARE CONSULTING OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,\r
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,\r
+ * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF\r
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING\r
+ * NEGLIGENCE OR OTHERWISE) ARISING IN  ANY WAY OUT OF THE USE OF THIS SOFTWARE,\r
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ */\r
+\r
+package jp.sourceforge.filelock;\r
+\r
+import java.util.ResourceBundle;\r
+\r
+/**\r
+ * <p>\r
+ * アプリケーションの情報を保持します。\r
+ * </p>\r
+ * \r
+ * @author $Author$\r
+ * @version $Rev$ $Date$\r
+ */\r
+public final class AppInfo {\r
+\r
+    /**\r
+     * <p>\r
+     * アプリケーションの題名。\r
+     * </p>\r
+     */\r
+    private String title;\r
+\r
+    /**\r
+     * <p>\r
+     * アプリケーションのバージョン。\r
+     * </p>\r
+     */\r
+    private String version;\r
+\r
+    /**\r
+     * <p>\r
+     * アプリケーションの著作権情報。\r
+     * </p>\r
+     */\r
+    private String copyright;\r
+\r
+    /**\r
+     * <p>\r
+     * 「filelock.properties」からアプリケーションの情報を読み込み、{@link AppInfo}クラスを初期化します。\r
+     * </p>\r
+     */\r
+    public AppInfo() {\r
+        ResourceBundle rb = ResourceBundle.getBundle("filelock");\r
+        this.title = rb.getString("app.title");\r
+        this.version = rb.getString("app.version");\r
+        this.copyright = rb.getString("app.copyright");\r
+    }\r
+\r
+    /**\r
+     * <p>\r
+     * アプリケーションの題名を返します。\r
+     * </p>\r
+     * \r
+     * @return アプリケーションの題名。\r
+     */\r
+    public String getTitle() {\r
+        return this.title;\r
+    }\r
+\r
+    /**\r
+     * <p>\r
+     * アプリケーションのバージョンを返します。\r
+     * </p>\r
+     * \r
+     * @return アプリケーションのバージョン。\r
+     */\r
+    public String getVersion() {\r
+        return this.version;\r
+    }\r
+\r
+    /**\r
+     * <p>\r
+     * アプリケーションの著作権情報を返します。\r
+     * </p>\r
+     * \r
+     * @return アプリケーションの著作権情報。\r
+     */\r
+    public String getCopyright() {\r
+        return this.copyright;\r
+    }\r
+\r
+}\r
index 1ecad61..7d4d62b 100644 (file)
@@ -60,6 +60,15 @@ public final class ConsoleMain {
      *             失敗した場合。\r
      */\r
     public static void main(String[] args) throws IOException {\r
+        if (args.length == 0) {\r
+            AppInfo appInfo = new AppInfo();\r
+            System.out.println(appInfo.getTitle() + " " + appInfo.getVersion());\r
+            System.out.println(appInfo.getCopyright());\r
+            System.out.println();\r
+            System.out.println("Usage: filelock [file]*");\r
+            System.out.println("    file ロックするファイル、またはディレクトリ。");\r
+        }\r
+\r
         FileLockUtil flu = new FileLockUtil(args);\r
 \r
         Map<String, Boolean> lockStateMap = new TreeMap<String, Boolean>();\r
index 526c301..fbf7172 100644 (file)
@@ -1,6 +1,96 @@
+\r
 package jp.sourceforge.filelock;\r
 \r
+import java.awt.BorderLayout;\r
+import java.awt.event.ActionEvent;\r
+import java.awt.event.ActionListener;\r
+import java.awt.event.KeyEvent;\r
+import java.awt.event.WindowAdapter;\r
+import java.awt.event.WindowEvent;\r
+import java.io.IOException;\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+import java.util.Map;\r
+import java.util.ResourceBundle;\r
+import java.util.TreeMap;\r
+\r
+import javax.swing.JButton;\r
+import javax.swing.JFrame;\r
+import javax.swing.JList;\r
+import javax.swing.JPanel;\r
+import javax.swing.UIManager;\r
+import javax.swing.UnsupportedLookAndFeelException;\r
+import javax.swing.WindowConstants;\r
+\r
+public class SwingMain extends JFrame {\r
+\r
+    private JList                  lockList;\r
+\r
+    private JButton                closeButton;\r
+\r
+    private transient FileLockUtil fileLockUtil;\r
+\r
+    public static void main(String[] args) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException {\r
+        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());\r
+\r
+        SwingMain one = new SwingMain(args);\r
+        one.setVisible(true);\r
+    }\r
+\r
+    public SwingMain(String[] args) throws IOException {\r
+        this.fileLockUtil = new FileLockUtil(args);\r
+\r
+        AppInfo appInfo = new AppInfo();\r
+\r
+        this.addWindowListener(new WindowAdapter() {\r
+\r
+            @Override\r
+            public void windowClosed(WindowEvent e) {\r
+                System.out.println("closed");\r
+                SwingMain.this.fileLockUtil.release();\r
+                System.exit(0);\r
+            }\r
+\r
+        });\r
+\r
+        this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);\r
+        this.setSize(400, 300);\r
+        this.setTitle(appInfo.getTitle() + " " + appInfo.getVersion());\r
+\r
+        JPanel panel = new JPanel();\r
+        panel.setLayout(new BorderLayout());\r
+        this.getContentPane().add(panel, BorderLayout.CENTER);\r
+\r
+        this.lockList = new JList();\r
+        Map<String, Boolean> lockStateMap = new TreeMap<String, Boolean>();\r
+        for (String path : this.fileLockUtil.lockFiles()) {\r
+            lockStateMap.put(path, true);\r
+        }\r
+        for (String path : this.fileLockUtil.lockFailFiles()) {\r
+            lockStateMap.put(path, false);\r
+        }\r
+        List<String> lockListItems = new ArrayList<String>();\r
+        for (Map.Entry<String, Boolean> entry : lockStateMap.entrySet()) {\r
+            if (entry.getValue()) {\r
+                lockListItems.add("LOCK " + entry.getKey());\r
+            } else {\r
+                lockListItems.add("FAIL " + entry.getKey());\r
+            }\r
+        }\r
+        this.lockList.setListData(lockListItems.toArray(new String[0]));\r
+        panel.add(this.lockList, BorderLayout.CENTER);\r
+\r
+        ResourceBundle rb = ResourceBundle.getBundle("filelock");\r
+        this.closeButton = new JButton(rb.getString("message.close"));\r
+        this.closeButton.setMnemonic(KeyEvent.VK_C);\r
+        this.closeButton.addActionListener(new ActionListener() {\r
+\r
+            public void actionPerformed(ActionEvent e) {\r
+                SwingMain.this.dispose();\r
+            }\r
 \r
-public class SwingMain {\r
+        });\r
+        panel.add(this.closeButton, BorderLayout.SOUTH);\r
+    }\r
 \r
 }\r
diff --git a/filelock/src/main/resources/filelock.properties b/filelock/src/main/resources/filelock.properties
new file mode 100644 (file)
index 0000000..4073140
--- /dev/null
@@ -0,0 +1,5 @@
+app.title=filelock\r
+app.version=0.1.0\r
+app.copyright=Copyright (C) 2007 uguu at users.sourceforge.jp, All Rights Reserved.\r
+\r
+message.close=\u9589\u3058\u308b(C)\r