Autopsy  4.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
ThumbnailViewChildren.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2011-15 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.corecomponents;
20 
21 import java.util.ArrayList;
22 import java.util.HashMap;
23 import java.util.List;
24 import org.openide.nodes.AbstractNode;
25 import org.openide.nodes.Children;
26 import org.openide.nodes.Node;
27 import org.openide.util.lookup.Lookups;
30 import org.sleuthkit.datamodel.Content;
31 
42 class ThumbnailViewChildren extends Children.Keys<Integer> {
43 
44  static final int IMAGES_PER_PAGE = 200;
45  private Node parent;
46  private final HashMap<Integer, List<Node>> pages = new HashMap<>();
47  private int totalImages = 0;
48  private int totalPages = 0;
49  private int iconSize = ImageUtils.ICON_SIZE_MEDIUM;
50  private static final Logger logger = Logger.getLogger(ThumbnailViewChildren.class.getName());
51 
55  ThumbnailViewChildren(Node arg, int iconSize) {
56  super(true); //support lazy loading
57 
58  this.parent = arg;
59  this.iconSize = iconSize;
60  }
61 
62  @Override
63  protected void addNotify() {
64  super.addNotify();
65 
66  setupKeys();
67  }
68 
69  int getTotalPages() {
70  return totalPages;
71  }
72 
73  int getTotalImages() {
74  return totalImages;
75  }
76 
77  private void setupKeys() {
78  //divide the supported content into buckets
79  totalImages = 0;
80  //TODO when lazy loading of original nodes is fixed
81  //we should be asking the datamodel for the children instead
82  //and not counting the children nodes (which might not be preloaded at this point)
83  final List<Node> suppContent = new ArrayList<>();
84  for (Node child : parent.getChildren().getNodes()) {
85  if (isSupported(child)) {
86  ++totalImages;
87  //Content content = child.getLookup().lookup(Content.class);
88  //suppContent.add(content);
89  suppContent.add(child);
90  }
91  }
92 
93  if (totalImages == 0) {
94  return;
95  }
96 
97  totalPages = 0;
98  if (totalImages < IMAGES_PER_PAGE) {
99  totalPages = 1;
100  } else {
101  totalPages = totalImages / IMAGES_PER_PAGE;
102  if (totalPages % totalImages != 0) {
103  ++totalPages;
104  }
105  }
106 
107  int prevImages = 0;
108  for (int page = 1; page <= totalPages; ++page) {
109  int toAdd = Math.min(IMAGES_PER_PAGE, totalImages - prevImages);
110  List<Node> pageContent = suppContent.subList(prevImages, prevImages + toAdd);
111  pages.put(page, pageContent);
112  prevImages += toAdd;
113  }
114 
115  Integer[] pageNums = new Integer[totalPages];
116  for (int i = 0; i < totalPages; ++i) {
117  pageNums[i] = i + 1;
118  }
119  setKeys(pageNums);
120  }
121 
122  @Override
123  protected void removeNotify() {
124  super.removeNotify();
125  pages.clear();
126  totalImages = 0;
127  }
128 
129  @Override
130  protected Node[] createNodes(Integer pageNum) {
131  final ThumbnailPageNode pageNode = new ThumbnailPageNode(pageNum);
132  return new Node[]{pageNode};
133  }
134 
135  static boolean isSupported(Node node) {
136  if (node != null) {
137  Content content = node.getLookup().lookup(Content.class);
138  if (content != null) {
139  return ImageUtils.thumbnailSupported(content);
140  }
141  }
142  return false;
143  }
144 
145  public void setIconSize(int iconSize) {
146  this.iconSize = iconSize;
147  }
148 
153  private class ThumbnailPageNode extends AbstractNode {
154 
155  ThumbnailPageNode(Integer pageNum) {
156  super(new ThumbnailPageNodeChildren(pages.get(pageNum)), Lookups.singleton(pageNum));
157  setName(Integer.toString(pageNum));
158  int from = 1 + ((pageNum - 1) * IMAGES_PER_PAGE);
159  int showImages = Math.min(IMAGES_PER_PAGE, totalImages - (from - 1));
160  int to = from + showImages - 1;
161  setDisplayName(from + "-" + to);
162 
163  this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/Folder-icon.png"); //NON-NLS
164 
165  }
166  }
167 
168  //TODO insert node at beginning pressing which goes back to page view
169  private class ThumbnailPageNodeChildren extends Children.Keys<Node> {
170 
171  //wrapped original nodes
172  private List<Node> contentImages = null;
173 
174  ThumbnailPageNodeChildren(List<Node> contentImages) {
175  super(true);
176 
177  this.contentImages = contentImages;
178  }
179 
180  @Override
181  protected void addNotify() {
182  super.addNotify();
183 
184  setKeys(contentImages);
185  }
186 
187  @Override
188  protected void removeNotify() {
189  super.removeNotify();
190 
191  setKeys(new ArrayList<Node>());
192  }
193 
194  @Override
195  protected Node[] createNodes(Node wrapped) {
196  if (wrapped != null) {
197  final ThumbnailViewNode thumb = new ThumbnailViewNode(wrapped, iconSize);
198  return new Node[]{thumb};
199  } else {
200  return new Node[]{};
201  }
202  }
203  }
204 }

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