22 package org.sleuthkit.autopsy.rejview;
24 import com.williballenthin.rejistry.RegistryParseException;
25 import com.williballenthin.rejistry.RegistryValue;
26 import java.awt.BorderLayout;
27 import java.awt.Dimension;
28 import javax.swing.table.TableColumn;
29 import javax.swing.table.TableColumnModel;
30 import java.io.UnsupportedEncodingException;
31 import java.text.SimpleDateFormat;
32 import java.util.Date;
33 import java.util.Iterator;
34 import java.util.logging.Level;
35 import javax.swing.BorderFactory;
36 import javax.swing.JLabel;
37 import javax.swing.JScrollPane;
38 import javax.swing.JTable;
39 import javax.swing.SwingConstants;
40 import org.openide.util.NbBundle.Messages;
51 @Messages({
"RejTreeKeyView.failedToParse.keyName=FAILED TO PARSE KEY NAME",
52 "RejTreeKeyView.columns.name=Name",
53 "RejTreeKeyView.columns.type=Type",
54 "RejTreeKeyView.columns.value=Value",
55 "RejTreeKeyView.metadataBorder.title=Metadata",
56 "RejTreeKeyView.valuesBorder.title=Values",
57 "RejTreeKeyView.template.name=Name:",
58 "RejTreeKeyView.template.numberOfSubkeys=Number of subkeys:",
59 "RejTreeKeyView.template.numberOfValues=Number of values:",
60 "RejTreeKeyView.template.dateTime=Modification Time:"})
62 super(
new BorderLayout());
70 String metadataTemplate =
"<html><i>"
71 + Bundle.RejTreeKeyView_template_name()
72 +
"</i><b> %1$s</b><br/><i>"
73 + Bundle.RejTreeKeyView_template_numberOfSubkeys()
75 + Bundle.RejTreeKeyView_template_numberOfValues()
77 + Bundle.RejTreeKeyView_template_dateTime()
78 +
"</i> %4$s</br></html>";
85 keyName = node.getKey().getName();
86 }
catch (UnsupportedEncodingException ex) {
87 logger.log(Level.WARNING,
"Failed to parse key name", ex);
88 keyName = Bundle.RejTreeKeyView_failedToParse_keyName();
92 numSubkeys = node.getKey().getSubkeyList().size();
93 }
catch (RegistryParseException ex) {
94 logger.log(Level.WARNING,
"Failed to get subkeylist from key", ex);
99 numValues = node.getKey().getValueList().size();
100 }
catch (RegistryParseException ex) {
101 logger.log(Level.WARNING,
"Failed to get value list from key", ex);
105 Date date =
new java.util.Date(node.getKey().getTimestamp().getTimeInMillis());
106 SimpleDateFormat sdf =
new java.text.SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss z");
107 sdf.setTimeZone(java.util.TimeZone.getTimeZone(
"GMT+0"));
108 dateTime = sdf.format(date);
110 JLabel metadataLabel =
new JLabel(String.format(metadataTemplate, keyName, numSubkeys, numValues, dateTime), JLabel.LEFT);
111 metadataLabel.setBorder(BorderFactory.createTitledBorder(Bundle.RejTreeKeyView_metadataBorder_title()));
112 metadataLabel.setVerticalAlignment(SwingConstants.TOP);
114 String[] columnNames = {Bundle.RejTreeKeyView_columns_name(), Bundle.RejTreeKeyView_columns_type(), Bundle.RejTreeKeyView_columns_value()};
115 Object[][] data =
new Object[numValues][3];
118 Iterator<RegistryValue> valit = node.getKey().getValueList().iterator();
120 while (valit.hasNext()) {
121 RegistryValue val = valit.next();
122 if (val.getName().length() == 0) {
125 data[i][0] = val.getName();
127 data[i][1] = val.getValueType().toString();
128 data[i][2] = RegeditExeValueFormatter.format(val.getValue());
131 }
catch (RegistryParseException | UnsupportedEncodingException ex) {
132 logger.log(Level.WARNING,
"Error while getting RegistryValues.", ex);
136 JTable table =
new JTable(data, columnNames);
137 table.setAutoCreateRowSorter(
true);
138 table.setCellSelectionEnabled(
false);
139 table.setRowSelectionAllowed(
true);
140 table.setIntercellSpacing(
new Dimension(10, 1));
144 if (table.getColumnCount() > 0) {
145 int width[] =
new int[table.getColumnCount()];
147 for (
int j = 0; j < width.length; j++) {
148 TableColumn column = table.getColumnModel().getColumn(j);
149 int w = (int) table.getTableHeader().getDefaultRenderer().getTableCellRendererComponent(table, column.getIdentifier(),
false,
false, -1, j).getPreferredSize().getWidth();
151 if (table.getRowCount() > 0) {
152 for (
int i = 0; i < table.getRowCount(); i++) {
153 int pw = (int) table.getCellRenderer(i, j).getTableCellRendererComponent(table, table.getValueAt(i, j),
false,
false, i, j).getPreferredSize().getWidth();
157 width[j] += w + table.getIntercellSpacing().width;
158 total += w + table.getIntercellSpacing().width;
160 width[width.length - 1] += table.getVisibleRect().width - total;
161 TableColumnModel columnModel = table.getColumnModel();
162 for (
int j = 0; j < width.length; j++) {
163 TableColumn column = columnModel.getColumn(j);
164 table.getTableHeader().setResizingColumn(column);
165 column.setWidth(width[j]);
169 JScrollPane valuesPane =
new JScrollPane(table);
170 valuesPane.setBorder(BorderFactory.createTitledBorder(Bundle.RejTreeKeyView_valuesBorder_title()));
172 this.add(metadataLabel, BorderLayout.NORTH);
173 this.add(valuesPane, BorderLayout.CENTER);
RejTreeKeyView(RejTreeKeyNode node)
static final Logger logger
static final long serialVersionUID
synchronized static Logger getLogger(String name)