Swing/RenameIfCanWriteFileChooser のバックアップ差分(No.5)
- バックアップ一覧
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- バックアップ を表示
- Swing/RenameIfCanWriteFileChooser へ行く。
- 1 (2011-10-21 (金) 02:12:49)
- 2 (2011-12-15 (木) 20:34:29)
- 3 (2012-12-16 (日) 01:40:28)
- 4 (2013-09-05 (木) 00:39:56)
- 5 (2014-11-25 (火) 03:03:31)
- 6 (2015-02-05 (木) 14:35:02)
- 7 (2016-08-19 (金) 16:19:26)
- 8 (2017-10-05 (木) 14:30:25)
- 9 (2019-04-04 (木) 14:26:18)
- 10 (2021-01-14 (木) 17:59:30)
- 11 (2023-07-27 (木) 18:37:23)
- 12 (2024-03-18 (月) 14:17:20)
- 追加された行はこの色です。
- 削除された行はこの色です。
TITLE:JFileChooserで読み取り専用ファイルのリネームを禁止 #navi(../) #tags(JFileChooser, File, BasicDirectoryModel) RIGHT:Posted by &author(aterai); at 2011-10-17 *JFileChooserで読み取り専用ファイルのリネームを禁止 [#u21472b3] ``JFileChooser``で読み取り専用属性ファイルのリネームを禁止します。 --- title: JFileChooserで読み取り専用ファイルのリネームを禁止 tags: [JFileChooser, File, BasicDirectoryModel] author: aterai pubdate: 2011-10-17T12:57:18+09:00 description: JFileChooserで読み取り専用属性ファイルのリネームを禁止します。 --- * 概要 [#u21472b3] `JFileChooser`で読み取り専用属性ファイルのリネームを禁止します。 //-&jnlp; -&jar; -&zip; #download(https://lh5.googleusercontent.com/-7ODSj6DaIig/TpsQEay0NqI/AAAAAAAABDs/8fz14wjADj0/s800/RenameIfCanWriteFileChooser.png) //#screenshot #ref(https://lh5.googleusercontent.com/-7ODSj6DaIig/TpsQEay0NqI/AAAAAAAABDs/8fz14wjADj0/s800/RenameIfCanWriteFileChooser.png) **サンプルコード [#y089b0c5] * サンプルコード [#y089b0c5] #code(link){{ class CanWriteFileChooserUI extends MetalFileChooserUI{ protected CanWriteFileChooserUI(JFileChooser chooser) { super(chooser); } public static ComponentUI createUI(JComponent c) { return new CanWriteFileChooserUI((JFileChooser)c); } private BasicDirectoryModel model2 = null; @Override public void createModel() { if(model2!=null) { model2.invalidateFileCache(); } model2 = new BasicDirectoryModel(getFileChooser()) { @Override public boolean renameFile(File oldFile, File newFile) { return oldFile.canWrite()?super.renameFile(oldFile, newFile):false; } }; } @Override public BasicDirectoryModel getModel() { return model2; } } }} **解説 [#u34dc296] 上記のサンプルでは、``BasicDirectoryModel#renameFile(...)``をオーバーライドして取り専用属性ファイルのリネームを確定しようとすると警告ダイアログが表示されるようになっています。 * 解説 [#u34dc296] 上記のサンプルでは、`BasicDirectoryModel#renameFile(...)`をオーバーライドして取り専用属性ファイルのリネームを確定しようとすると警告ダイアログが表示されるようになっています。 ---- ``sun.swing.FilePane#canWrite(File)``をオーバーライドすれば、編集開始自体を禁止にすることもできそうですが、``MetalFileChooserUI``などの``UI``で``FilePane``が``private``になっているためかなり面倒です。 `sun.swing.FilePane#canWrite(File)`をオーバーライドすれば、編集開始自体を禁止にすることもできそうですが、`MetalFileChooserUI`などの`UI`で`FilePane`が`private`になっているためかなり面倒です。 **参考リンク [#ta778ea1] -[https://forums.oracle.com/forums/thread.jspa?threadID=2298004 OTN Discussion Forums : How does the JFileChooser "readOnly" ...] -[[JFileChooserを編集不可にする>Swing/ROFileChooser]] * 参考リンク [#ta778ea1] - [https://forums.oracle.com/thread/2300004 Swing - How does the JFileChooser "readOnly" property work?] - [[JFileChooserを編集不可にする>Swing/ROFileChooser]] **コメント [#rf34c8a6] * コメント [#rf34c8a6] #comment #comment