回答編集履歴
2
日付チェックをレンダラ側に移動
answer
CHANGED
@@ -2,8 +2,7 @@
|
|
2
2
|
コンソールから実行する場合は, パラメータとしてHOMEとなるフォルダを指定してください.
|
3
3
|
パラメータ無しで実行すると, 内部で定義している DEFAULT_HOME_PATH = "T:\"(私の環境でのテンポラリ) が指定されたものとして動きますので, 必要に応じて DEFAULT_HOME_PATH を変えてください.
|
4
4
|
|
5
|
-
日付のチェックは getListCellRendererComponent 内で fileItem.
|
5
|
+
日付のチェックは getListCellRendererComponent 内で fileItem.lastModified.after(condition) として行っています.
|
6
|
-
fileItem クラスの lessThan メソッドは
|
7
6
|
```java
|
8
7
|
lastModified = Calendar.getInstance();
|
9
8
|
lastModified.setTimeInMillis(file.lastModified());
|
@@ -13,7 +12,7 @@
|
|
13
12
|
Calendar conditions = Calendar.getInstance();
|
14
13
|
conditions.add(Calendar.DATE, -30);
|
15
14
|
```
|
16
|
-
として現在日時から 30日を引いた Calendar を
|
15
|
+
として現在日時から 30日を引いた Calendar を比較しています.
|
17
16
|
このように表示の度にチェックしている為, フラグ等は要らなくなっています.
|
18
17
|
|
19
18
|
表示する名前やフラグ等を全て配列に準備して, 後は表示だけを行う形のほうが速いとお考えかも知れませんが, 速さはメモリの使用量とほぼトレードオフです. 巨大な配列等は好ましくないと思います.
|
@@ -175,7 +174,6 @@
|
|
175
174
|
lastModified.setTimeInMillis(file.lastModified());
|
176
175
|
}
|
177
176
|
boolean isDirectory() { return file.isDirectory(); }
|
178
|
-
boolean lessThan(Calendar conditions) { return lastModified.after(conditions); }
|
179
177
|
@Override
|
180
178
|
public String toString() {
|
181
179
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
|
@@ -194,7 +192,7 @@
|
|
194
192
|
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
|
195
193
|
JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
|
196
194
|
FileItem fileItem = (FileItem)value;
|
197
|
-
if(condition != null && fileItem.
|
195
|
+
if(condition != null && fileItem.lastModified.after(condition)) { //更新日チェック
|
198
196
|
label.setForeground(foreground);
|
199
197
|
}
|
200
198
|
return label;
|
1
フォルダ表示時の■付加処理を移動
answer
CHANGED
@@ -179,7 +179,8 @@
|
|
179
179
|
@Override
|
180
180
|
public String toString() {
|
181
181
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
|
182
|
+
String iconDummy = (isDirectory() ? "■" : " ");
|
182
|
-
return file.getName() + " (" + dateFormat.format(new Date(file.lastModified())) + ")";
|
183
|
+
return iconDummy + " "+ file.getName() + " (" + dateFormat.format(new Date(file.lastModified())) + ")";
|
183
184
|
}
|
184
185
|
}
|
185
186
|
|
@@ -196,11 +197,6 @@
|
|
196
197
|
if(condition != null && fileItem.lessThan(condition)) { //更新日チェック
|
197
198
|
label.setForeground(foreground);
|
198
199
|
}
|
199
|
-
if(fileItem.isDirectory()) {//フォルダは
|
200
|
-
label.setText("■ "+value.toString());//先頭に■を追加(フォルダアイコンのつもり)
|
201
|
-
} else {//他は
|
202
|
-
label.setText(" "+value.toString());//名前の位置を合わせるため全角空白を追加
|
203
|
-
}
|
204
200
|
return label;
|
205
201
|
}
|
206
202
|
/**
|