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;
49 private final List<UpdateWrapper>
textViewers =
new ArrayList<>();
59 Collection<? extends TextViewer> dcvs = Lookup.getDefault().lookupAll(
TextViewer.class);
69 javax.swing.JScrollPane scrollTab =
new javax.swing.JScrollPane(dcv.
getComponent());
70 scrollTab.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_NEVER);
77 for (
int tab = 0; tab < numTabs; ++tab) {
91 boolean isSupported(Node node) {
92 for (UpdateWrapper textViewer : textViewers) {
93 if (textViewer.isSupported(node)) {
109 int isPreffered(Node node) {
110 int max = ViewerPriority.viewerPriority.LevelOne.getFlag();
111 for (UpdateWrapper textViewer : textViewers) {
112 if (textViewer.isSupported(node)) {
113 max = Integer.max(max, textViewer.isPreferred(node));
119 @Messages({
"TextContentViewerPanel.defaultName=Text"})
123 this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
126 String defaultName = Bundle.TextContentViewerPanel_defaultName();
128 if (selectedNode == null) {
129 setName(defaultName);
131 Content content = selectedNode.getLookup().lookup(Content.class);
132 if (content != null) {
133 String path = defaultName;
135 path = content.getUniquePath();
136 }
catch (TskCoreException ex) {
137 logger.log(Level.SEVERE,
"Exception while calling Content.getUniquePath() for " + content.toString(), ex);
141 setName(defaultName);
145 currentNode = selectedNode;
149 this.setCursor(null);
162 if (listeningToTabbedPane ==
false) {
164 listeningToTabbedPane =
true;
169 int maxPreferred = 0;
170 int preferredViewerIndex = 0;
171 for (
int i = 0; i < totalTabs; ++i) {
173 dcv.resetComponent();
176 if ((selectedNode == null) || (dcv.isSupported(selectedNode) ==
false)) {
182 int currentPreferred = dcv.isPreferred(selectedNode);
183 if (currentPreferred > maxPreferred) {
184 preferredViewerIndex = i;
185 maxPreferred = currentPreferred;
196 dcv.resetComponent();
198 dcv.setNode(selectedNode);
213 JTabbedPane pane = (JTabbedPane) evt.getSource();
216 int currentTab = pane.getSelectedIndex();
217 if (currentTab != -1 && pane.isEnabledAt(currentTab)) {
219 if (dcv.isOutdated()) {
221 this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
223 dcv.setNode(currentNode);
225 this.setCursor(null);
236 @SuppressWarnings(
"unchecked")
242 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(
this);
243 this.setLayout(layout);
244 layout.setHorizontalGroup(
245 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
246 .addGap(0, 50, Short.MAX_VALUE)
247 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
250 layout.setVerticalGroup(
251 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
252 .addGap(0, 27, Short.MAX_VALUE)
253 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
273 this.outdated =
true;
276 void setNode(Node selectedNode) {
277 this.wrapped.
setNode(selectedNode);
278 this.outdated =
false;
281 void resetComponent() {
283 this.outdated =
true;
286 boolean isOutdated() {
290 boolean isSupported(Node node) {
294 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