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.util.Iterator;
32 import java.util.logging.Level;
33 import javax.swing.BorderFactory;
34 import javax.swing.JLabel;
35 import javax.swing.JScrollPane;
36 import javax.swing.JTable;
37 import javax.swing.SwingConstants;
38 import org.openide.util.NbBundle.Messages;
49 @Messages({
"RejTreeKeyView.failedToParse.keyName=FAILED TO PARSE KEY NAME",
50 "RejTreeKeyView.columns.name=Name",
51 "RejTreeKeyView.columns.type=Type",
52 "RejTreeKeyView.columns.value=Value",
53 "RejTreeKeyView.metadataBorder.title=Metadata",
54 "RejTreeKeyView.valuesBorder.title=Values",
55 "RejTreeKeyView.template.name=Name:",
56 "RejTreeKeyView.template.numberOfSubkeys=Number of subkeys:",
57 "RejTreeKeyView.template.numberOfValues=Number of values:"})
59 super(
new BorderLayout());
66 String metadataTemplate =
"<html><i>"
67 + Bundle.RejTreeKeyView_template_name()
68 +
"</i><b> %1$s</b><br/><i>"
69 + Bundle.RejTreeKeyView_template_numberOfSubkeys()
71 + Bundle.RejTreeKeyView_template_numberOfValues()
72 +
"</i> %3$d<br/></html>";
78 keyName = node.getKey().getName();
79 }
catch (UnsupportedEncodingException ex) {
80 logger.log(Level.WARNING,
"Failed to parse key name", ex);
81 keyName = Bundle.RejTreeKeyView_failedToParse_keyName();
85 numSubkeys = node.getKey().getSubkeyList().size();
86 }
catch (RegistryParseException ex) {
87 logger.log(Level.WARNING,
"Failed to get subkeylist from key", ex);
92 numValues = node.getKey().getValueList().size();
93 }
catch (RegistryParseException ex) {
94 logger.log(Level.WARNING,
"Failed to get value list from key", ex);
98 JLabel metadataLabel =
new JLabel(String.format(metadataTemplate, keyName, numSubkeys, numValues), JLabel.LEFT);
99 metadataLabel.setBorder(BorderFactory.createTitledBorder(Bundle.RejTreeKeyView_metadataBorder_title()));
100 metadataLabel.setVerticalAlignment(SwingConstants.TOP);
102 String[] columnNames = {Bundle.RejTreeKeyView_columns_name(), Bundle.RejTreeKeyView_columns_type(), Bundle.RejTreeKeyView_columns_value()};
103 Object[][] data =
new Object[numValues][3];
106 Iterator<RegistryValue> valit = node.getKey().getValueList().iterator();
108 while (valit.hasNext()) {
109 RegistryValue val = valit.next();
110 if (val.getName().length() == 0) {
113 data[i][0] = val.getName();
115 data[i][1] = val.getValueType().toString();
116 data[i][2] = RegeditExeValueFormatter.format(val.getValue());
119 }
catch (RegistryParseException | UnsupportedEncodingException ex) {
120 logger.log(Level.WARNING,
"Error while getting RegistryValues.", ex);
124 JTable table =
new JTable(data, columnNames);
125 table.setAutoCreateRowSorter(
true);
126 table.setCellSelectionEnabled(
false);
127 table.setRowSelectionAllowed(
true);
128 table.setIntercellSpacing(
new Dimension(10, 1));
132 if (table.getColumnCount() > 0) {
133 int width[] =
new int[table.getColumnCount()];
135 for (
int j = 0; j < width.length; j++) {
136 TableColumn column = table.getColumnModel().getColumn(j);
137 int w = (int) table.getTableHeader().getDefaultRenderer().getTableCellRendererComponent(table, column.getIdentifier(),
false,
false, -1, j).getPreferredSize().getWidth();
139 if (table.getRowCount() > 0) {
140 for (
int i = 0; i < table.getRowCount(); i++) {
141 int pw = (int) table.getCellRenderer(i, j).getTableCellRendererComponent(table, table.getValueAt(i, j),
false,
false, i, j).getPreferredSize().getWidth();
145 width[j] += w + table.getIntercellSpacing().width;
146 total += w + table.getIntercellSpacing().width;
148 width[width.length - 1] += table.getVisibleRect().width - total;
149 TableColumnModel columnModel = table.getColumnModel();
150 for (
int j = 0; j < width.length; j++) {
151 TableColumn column = columnModel.getColumn(j);
152 table.getTableHeader().setResizingColumn(column);
153 column.setWidth(width[j]);
157 JScrollPane valuesPane =
new JScrollPane(table);
158 valuesPane.setBorder(BorderFactory.createTitledBorder(Bundle.RejTreeKeyView_valuesBorder_title()));
160 this.add(metadataLabel, BorderLayout.NORTH);
161 this.add(valuesPane, BorderLayout.CENTER);
RejTreeKeyView(RejTreeKeyNode node)
static final Logger logger
static final long serialVersionUID
synchronized static Logger getLogger(String name)