2 * Copyright (C) 2007 u6k.yu1@gmail.com, All Rights Reserved.
\r
4 * Redistribution and use in source and binary forms, with or without
\r
5 * modification, are permitted provided that the following conditions
\r
8 * 1. Redistributions of source code must retain the above copyright
\r
9 * notice, this list of conditions and the following disclaimer.
\r
11 * 2. Redistributions in binary form must reproduce the above copyright
\r
12 * notice, this list of conditions and the following disclaimer in the
\r
13 * documentation and/or other materials provided with the distribution.
\r
15 * 3. Neither the name of Clarkware Consulting, Inc. nor the names of its
\r
16 * contributors may be used to endorse or promote products derived
\r
17 * from this software without prior written permission. For written
\r
18 * permission, please contact clarkware@clarkware.com.
\r
20 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
\r
21 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
\r
22 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
\r
23 * CLARKWARE CONSULTING OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
\r
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
\r
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
\r
26 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
\r
27 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
\r
28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
\r
29 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
32 package jp.gr.java_conf.u6k.filelock;
\r
34 import java.awt.BorderLayout;
\r
35 import java.awt.event.ActionEvent;
\r
36 import java.awt.event.ActionListener;
\r
37 import java.awt.event.KeyEvent;
\r
38 import java.awt.event.WindowAdapter;
\r
39 import java.awt.event.WindowEvent;
\r
40 import java.io.IOException;
\r
41 import java.util.ArrayList;
\r
42 import java.util.List;
\r
43 import java.util.Map;
\r
44 import java.util.ResourceBundle;
\r
45 import java.util.TreeMap;
\r
47 import javax.swing.JButton;
\r
48 import javax.swing.JFrame;
\r
49 import javax.swing.JList;
\r
50 import javax.swing.JPanel;
\r
51 import javax.swing.UIManager;
\r
52 import javax.swing.UnsupportedLookAndFeelException;
\r
53 import javax.swing.WindowConstants;
\r
54 import javax.swing.border.BevelBorder;
\r
58 * Swingアプリケーションとして起動するメイン・クラスです。
\r
62 * @version $Rev$ $Date$
\r
64 @SuppressWarnings("serial")
\r
65 public class SwingMain extends JFrame {
\r
72 private static final int WIDTH = 400;
\r
79 private static final int HEIGHT = 300;
\r
83 * ロック対象のファイルを表示するリスト。
\r
86 private JList lockList;
\r
93 private JButton closeButton;
\r
100 private transient FileLockUtil fileLockUtil;
\r
109 * @throws IOException
\r
112 public SwingMain(String[] args) throws IOException {
\r
113 this.fileLockUtil = new FileLockUtil(args);
\r
115 AppInfo appInfo = new AppInfo();
\r
117 this.addWindowListener(new WindowAdapter() {
\r
120 public void windowClosed(WindowEvent e) {
\r
121 SwingMain.this.fileLockUtil.release();
\r
127 this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
\r
128 this.setSize(SwingMain.WIDTH, SwingMain.HEIGHT);
\r
129 this.setTitle(appInfo.getTitle() + " " + appInfo.getVersion());
\r
131 JPanel panel = new JPanel();
\r
132 panel.setLayout(new BorderLayout());
\r
133 this.getContentPane().add(panel, BorderLayout.CENTER);
\r
135 this.lockList = new JList();
\r
136 this.lockList.setBorder(new BevelBorder(BevelBorder.LOWERED));
\r
137 Map<String, Boolean> lockStateMap = new TreeMap<String, Boolean>();
\r
138 for (String path : this.fileLockUtil.lockFiles()) {
\r
139 lockStateMap.put(path, true);
\r
141 for (String path : this.fileLockUtil.lockFailFiles()) {
\r
142 lockStateMap.put(path, false);
\r
144 List<String> lockListItems = new ArrayList<String>();
\r
145 for (Map.Entry<String, Boolean> entry : lockStateMap.entrySet()) {
\r
146 if (entry.getValue()) {
\r
147 lockListItems.add("LOCK " + entry.getKey());
\r
149 lockListItems.add("FAIL " + entry.getKey());
\r
152 this.lockList.setListData(lockListItems.toArray(new String[0]));
\r
153 panel.add(this.lockList, BorderLayout.CENTER);
\r
155 ResourceBundle rb = ResourceBundle.getBundle("filelock");
\r
156 this.closeButton = new JButton(rb.getString("message.close"));
\r
157 this.closeButton.setMnemonic(KeyEvent.VK_C);
\r
158 this.closeButton.addActionListener(new ActionListener() {
\r
160 public void actionPerformed(ActionEvent e) {
\r
161 SwingMain.this.dispose();
\r
165 panel.add(this.closeButton, BorderLayout.SOUTH);
\r
170 * アプリケーションのエントリーポイントです。
\r
175 * @throws IOException
\r
177 * @throws ClassNotFoundException
\r
178 * レイアウト・マネージャの設定に失敗した場合。
\r
179 * @throws InstantiationException
\r
180 * レイアウト・マネージャの設定に失敗した場合。
\r
181 * @throws IllegalAccessException
\r
182 * レイアウト・マネージャの設定に失敗した場合。
\r
183 * @throws UnsupportedLookAndFeelException
\r
184 * レイアウト・マネージャの設定に失敗した場合。
\r
186 public static void main(String[] args) throws IOException, ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException {
\r
187 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
\r
189 SwingMain one = new SwingMain(args);
\r
190 one.setVisible(true);
\r