Skip to content

Commit

Permalink
Replaced SimpleDateFormat in ZipFileChooser and replaced arrays with …
Browse files Browse the repository at this point in the history
…Lists
  • Loading branch information
oscargus committed Jul 13, 2016
1 parent ab3340d commit 47754ad
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/main/java/net/sf/jabref/importer/ZipFileChooser.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.Enumeration;
Expand Down Expand Up @@ -150,15 +154,15 @@ public ZipFileChooser(ImportCustomizationDialog importCustomizationDialog, ZipFi
* @param zipFile Zip-File
* @return entries that can be selected
*/
private static ZipEntry[] getSelectableZipEntries(ZipFile zipFile) {
private static List<ZipEntry> getSelectableZipEntries(ZipFile zipFile) {
List<ZipEntry> entries = new ArrayList<>();
Enumeration<? extends ZipEntry> e = zipFile.entries();
for (ZipEntry entry : Collections.list(e)) {
if (!entry.isDirectory() && entry.getName().endsWith(".class")) {
entries.add(entry);
}
}
return entries.toArray(new ZipEntry[entries.size()]);
return entries;
}

/*
Expand Down Expand Up @@ -188,13 +192,13 @@ public Dimension getSize() {
*/
private static class ZipFileChooserTableModel extends AbstractTableModel {

private final String[] columnNames = new String[] {Localization.lang("Name"),
Localization.lang("Last modified"), Localization.lang("Size")};
private final ZipEntry[] rows;
private final List<String> columnNames = Arrays.asList(Localization.lang("Name"),
Localization.lang("Last modified"), Localization.lang("Size"));
private final List<ZipEntry> rows;
private final ZipFile zipFile;


ZipFileChooserTableModel(ZipFile zipFile, ZipEntry[] rows) {
ZipFileChooserTableModel(ZipFile zipFile, List<ZipEntry> rows) {
super();
this.rows = rows;
this.zipFile = zipFile;
Expand All @@ -206,7 +210,7 @@ private static class ZipFileChooserTableModel extends AbstractTableModel {
*/
@Override
public int getColumnCount() {
return columnNames.length;
return columnNames.size();
}

/*
Expand All @@ -215,7 +219,7 @@ public int getColumnCount() {
*/
@Override
public int getRowCount() {
return this.rows.length;
return this.rows.size();
}

/*
Expand All @@ -224,7 +228,7 @@ public int getRowCount() {
*/
@Override
public String getColumnName(int col) {
return columnNames[col];
return columnNames.get(col);
}

/**
Expand All @@ -234,7 +238,7 @@ public String getColumnName(int col) {
* @return Zip file entry
*/
public ZipEntry getZipEntry(int rowIndex) {
return this.rows[rowIndex];
return this.rows.get(rowIndex);
}

/**
Expand All @@ -257,7 +261,9 @@ public Object getValueAt(int rowIndex, int columnIndex) {
if (columnIndex == 0) {
value = entry.getName();
} else if (columnIndex == 1) {
value = SimpleDateFormat.getDateTimeInstance().format(new Date(entry.getTime()));
value = ZonedDateTime.ofInstant(new Date(entry.getTime()).toInstant(),
ZoneId.systemDefault())
.format(DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM));
} else if (columnIndex == 2) {
value = entry.getSize();
}
Expand Down

0 comments on commit 47754ad

Please sign in to comment.