19 package org.sleuthkit.autopsy.contentviewers.textcontentviewer;
21 import java.awt.Cursor;
22 import java.beans.PropertyChangeEvent;
23 import java.util.ArrayList;
24 import java.util.Collection;
25 import java.util.List;
26 import java.util.logging.Level;
27 import javax.swing.JTabbedPane;
28 import javax.swing.event.ChangeEvent;
29 import javax.swing.event.ChangeListener;
30 import org.openide.nodes.Node;
31 import org.openide.util.Lookup;
32 import org.openide.util.NbBundle.Messages;
48 private final List<UpdateWrapper>
textViewers =
new ArrayList<>();
58 Collection<? extends TextViewer> dcvs = Lookup.getDefault().lookupAll(
TextViewer.class);
68 javax.swing.JScrollPane scrollTab =
new javax.swing.JScrollPane(dcv.
getComponent());
69 scrollTab.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_NEVER);
76 for (
int tab = 0; tab < numTabs; ++tab) {
90 boolean isSupported(Node node) {
91 for (UpdateWrapper textViewer : textViewers) {
92 if (textViewer.isSupported(node)) {
108 int isPreffered(Node node) {
110 for (UpdateWrapper textViewer : textViewers) {
111 if (textViewer.isSupported(node)) {
112 max = Integer.max(max, textViewer.isPreferred(node));
118 @Messages({
"TextContentViewerPanel.defaultName=Text"})
122 this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
125 String defaultName = Bundle.TextContentViewerPanel_defaultName();
127 if (selectedNode == null) {
128 setName(defaultName);
130 Content content = selectedNode.getLookup().lookup(Content.class);
131 if (content != null) {
132 String path = defaultName;
134 path = content.getUniquePath();
135 }
catch (TskCoreException ex) {
136 logger.log(Level.SEVERE,
"Exception while calling Content.getUniquePath() for " + content.toString(), ex);
140 setName(defaultName);
144 currentNode = selectedNode;
148 this.setCursor(null);
161 if (listeningToTabbedPane ==
false) {
163 listeningToTabbedPane =
true;
168 int maxPreferred = 0;
169 int preferredViewerIndex = 0;
170 for (
int i = 0; i < totalTabs; ++i) {
172 dcv.resetComponent();
175 if ((selectedNode == null) || (dcv.isSupported(selectedNode) ==
false)) {
181 int currentPreferred = dcv.isPreferred(selectedNode);
182 if (currentPreferred > maxPreferred) {
183 preferredViewerIndex = i;
184 maxPreferred = currentPreferred;
195 dcv.resetComponent();
197 dcv.setNode(selectedNode);
212 JTabbedPane pane = (JTabbedPane) evt.getSource();
215 int currentTab = pane.getSelectedIndex();
216 if (currentTab != -1) {
218 if (dcv.isOutdated()) {
220 this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
222 dcv.setNode(currentNode);
224 this.setCursor(null);
235 @SuppressWarnings(
"unchecked")
241 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
242 this.setLayout(layout);
243 layout.setHorizontalGroup(
244 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
245 .addGap(0, 50, Short.MAX_VALUE)
246 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
249 layout.setVerticalGroup(
250 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
251 .addGap(0, 27, Short.MAX_VALUE)
252 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
272 this.outdated =
true;
275 void setNode(Node selectedNode) {
276 this.wrapped.
setNode(selectedNode);
277 this.outdated =
false;
280 void resetComponent() {
282 this.outdated =
true;
285 boolean isOutdated() {
289 boolean isSupported(Node node) {
293 int isPreferred(Node node) {
boolean isSupported(Node node)
static final Logger logger
int isPreferred(Node node)
void stateChanged(ChangeEvent evt)
void setNode(Node selectedNode)
static boolean keepPreferredContentViewer()
void setupTabs(Node selectedNode)
TextContentViewerPanel(boolean isMain)
static final long serialVersionUID
TextViewer createInstance()
final List< UpdateWrapper > textViewers
synchronized static Logger getLogger(String name)
void propertyChange(PropertyChangeEvent evt)
boolean listeningToTabbedPane
void setNode(Node selectedNode)
javax.swing.JTabbedPane textViewerTabbedPane