Autopsy  4.19.3
Graphical digital forensics platform for The Sleuth Kit and other tools.
StatusIconCellRenderer.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2015-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.guiutils;
20 
21 import java.awt.Component;
22 import java.lang.reflect.InvocationTargetException;
23 import javax.swing.ImageIcon;
24 import javax.swing.JTable;
25 import static javax.swing.SwingConstants.CENTER;
26 import org.openide.nodes.Node;
27 import org.openide.util.ImageUtilities;
28 import org.openide.util.NbBundle.Messages;
30 
37 
38  private static final long serialVersionUID = 1L;
39  static final ImageIcon OK_ICON = new ImageIcon(ImageUtilities.loadImage("org/sleuthkit/autopsy/images/tick.png", false));
40  static final ImageIcon WARNING_ICON = new ImageIcon(ImageUtilities.loadImage("org/sleuthkit/autopsy/images/warning16.png", false));
41  static final ImageIcon ERROR_ICON = new ImageIcon(ImageUtilities.loadImage("org/sleuthkit/autopsy/images/cross-script.png", false));
42 
43  @Messages({
44  "StatusIconCellRenderer.tooltiptext.ok=OK",
45  "StatusIconCellRenderer.tooltiptext.warning=A warning occurred",
46  "StatusIconCellRenderer.tooltiptext.error=An error occurred"
47  })
48  @Override
49  public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
50  setHorizontalAlignment(CENTER);
51  Object switchValue = null;
52  if ((value instanceof NodeProperty)) {
53  //The Outline view has properties in the cell, the value contained in the property is what we want
54  try {
55  switchValue = ((Node.Property) value).getValue();
56  } catch (IllegalAccessException | InvocationTargetException ex) {
57  //Unable to get the value from the NodeProperty no Icon will be displayed
58  }
59  } else {
60  //JTables contain the value we want directly in the cell
61  switchValue = value;
62  }
63  if ((switchValue instanceof Status)) {
64  switch ((Status) switchValue) {
65  case OK:
66  setIcon(OK_ICON);
67  setToolTipText(org.openide.util.NbBundle.getMessage(StatusIconCellRenderer.class, "StatusIconCellRenderer.tooltiptext.ok"));
68  break;
69  case WARNING:
70  setIcon(WARNING_ICON);
71  setToolTipText(org.openide.util.NbBundle.getMessage(StatusIconCellRenderer.class, "StatusIconCellRenderer.tooltiptext.warning"));
72  break;
73  case ERROR:
74  setIcon(ERROR_ICON);
75  setToolTipText(org.openide.util.NbBundle.getMessage(StatusIconCellRenderer.class, "StatusIconCellRenderer.tooltiptext.error"));
76  break;
77  }
78  } else {
79  setIcon(null);
80  setText("");
81  }
82  grayCellIfTableNotEnabled(table, isSelected);
83 
84  return this;
85  }
86 
87  public enum Status {
88  OK,
90  ERROR
91  }
92 }
Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
void grayCellIfTableNotEnabled(JTable table, boolean isSelected)

Copyright © 2012-2022 Basis Technology. Generated on: Wed Sep 28 2022
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.