Autopsy  4.17.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
EpochTimeCellRenderer.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2018 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.contentviewers;
20 
21 import java.awt.Component;
22 import java.awt.Font;
23 import java.lang.reflect.InvocationTargetException;
24 import java.text.SimpleDateFormat;
25 import java.util.Date;
26 import java.util.logging.Level;
27 import javax.swing.JTable;
28 import javax.swing.table.DefaultTableCellRenderer;
29 import org.openide.nodes.Node;
31 
36 class EpochTimeCellRenderer extends DefaultTableCellRenderer {
37 
38  private static final long serialVersionUID = 1L;
39  private static final Logger LOGGER = Logger.getLogger(FileViewer.class.getName());
40 
41  private static final String FORMAT_STRING = "yyyy/MM/dd HH:mm:ss"; //NON-NLS
42  private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat(FORMAT_STRING);
43 
44  private final boolean renderAsEpoch;
45 
46  EpochTimeCellRenderer(boolean renderAsEpoch) {
47  this.renderAsEpoch = renderAsEpoch;
48  }
49 
50  @Override
51  public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
52 
53  // Set the forceground/background so its obvious when the cell is selected.
54  if (isSelected) {
55  super.setForeground(table.getSelectionForeground());
56  super.setBackground(table.getSelectionBackground());
57  } else {
58  super.setForeground( table.getForeground());
59  super.setBackground( table.getBackground());
60  }
61 
62  if (value == null) {
63  setText("");
64  }
65  else {
66  String textStr = "";
67  try {
68  // get the col property value
69  if (value instanceof Node.Property<?>) {
70  Node.Property<?> nodeProp = (Node.Property)value;
71  textStr = nodeProp.getValue().toString();
72  }
73 
74  if (renderAsEpoch) {
75  long epochTime = Long.parseUnsignedLong(textStr);
76  if (epochTime > 0 ) {
77  Font font = getFont();
78  setFont(font.deriveFont(font.getStyle() | Font.ITALIC));
79  setText(DATE_FORMAT.format(new Date(epochTime)));
80  }
81  else {
82  setText(textStr);
83  }
84  }
85  else { // Display raw data
86  setText(textStr);
87  }
88  }
89  catch (NumberFormatException e) {
90  setText(textStr);
91  LOGGER.log(Level.INFO, "Error converting column value to number.", e); //NON-NLS
92  } catch (IllegalAccessException | InvocationTargetException ex) {
93  setText("");
94  LOGGER.log(Level.SEVERE, "Error in getting column value.", ex); //NON-NLS
95  }
96  }
97 
98  return this;
99  }
100 
101  boolean isRenderingAsEpoch() {
102  return this.renderAsEpoch;
103  }
104 
105 }
synchronized static Logger getLogger(String name)
Definition: Logger.java:124

Copyright © 2012-2021 Basis Technology. Generated on: Tue Jan 19 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.