OSDN Git Service

Add new source files
[armadillo/armadillo1.git] / src / jp / sfjp / armadillo / ui / window / ListDialog.java
1 package jp.sfjp.armadillo.ui.window;
2
3 import java.awt.*;
4 import java.awt.event.*;
5 import java.io.*;
6 import java.text.*;
7 import java.util.*;
8 import java.util.List;
9 import javax.swing.*;
10 import javax.swing.table.*;
11 import jp.sfjp.armadillo.*;
12 import jp.sfjp.armadillo.archive.*;
13
14 public final class ListDialog extends JDialog {
15
16     static Logger log = Logger.getLogger(ListDialog.class);
17     static ResourceManager res = ResourceManager.getInstance("jp.sfjp.armadillo.ui.messages");
18
19     public ListDialog(final MainWindow mainWindow,
20                       final File src,
21                       ArchiveType type,
22                       ProgressNotifier progressNotifier) throws IOException {
23         super(mainWindow);
24         setTitle(String.format("%s", src.getAbsolutePath()));
25         setDefaultCloseOperation(DISPOSE_ON_CLOSE);
26         List<ArchiveEntry> infos = ArmadilloCommands.extractArchiveEntries(src, type);
27         Object[][] rowData = new Object[infos.size()][];
28         int i = -1;
29         DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
30         for (final ArchiveEntry entry : infos) {
31             final Object compsize;
32             if (entry.getCompressedSize() >= 0)
33                 compsize = entry.getCompressedSize();
34             else
35                 compsize = "";
36             final Object mtime = df.format(new Date(entry.getLastModified()));
37             Object[] row = {entry.getName(), entry.getMethodName(), entry.getSize(), compsize,
38                             mtime,};
39             rowData[++i] = row;
40         }
41         Object[] columnNames = {res.get("label.list.name"), res.get("label.list.method"),
42                                 res.get("label.list.size"), res.get("label.list.compsize"),
43                                 res.get("label.list.mtime")};
44         final JTable t = new JTable(rowData, columnNames);
45         t.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
46         TableColumnModel cm = t.getColumnModel();
47         cm.getColumn(0).setPreferredWidth(256);
48         cm.getColumn(4).setPreferredWidth(124);
49         t.getTableHeader().setResizingAllowed(false);
50         JScrollPane sp = new JScrollPane(t,
51                                          ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
52                                          ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
53         add(sp, BorderLayout.CENTER);
54         JButton button = new JButton(new AbstractAction(res.get("button.extractSelectedEntries")) {
55             @Override
56             public void actionPerformed(ActionEvent e) {
57                 Set<String> targetSet = new LinkedHashSet<String>();
58                 long totalSize = 0L;
59                 for (final int rowIndex : t.getSelectedRows()) {
60                     targetSet.add(String.valueOf(t.getValueAt(rowIndex, 0)));
61                     totalSize += toLong(t.getValueAt(rowIndex, 3));
62                 }
63                 mainWindow.startExtractAction(src, totalSize, targetSet);
64             }
65             private long toLong(Object o) {
66                 if (o == null)
67                     return 0;
68                 final String s = String.valueOf(o).trim();
69                 if (s.isEmpty())
70                     return 0;
71                 assert s.matches("\\d+");
72                 return Long.parseLong(s);
73             }
74         });
75         add(button, BorderLayout.NORTH);
76         pack();
77     }
78
79     void showInfoList(final File archiveFile, List<ArchiveEntry> entryList) {
80         setVisible(true);
81     }
82
83 }