Autopsy  3.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 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;
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<Integer, List<Node>>();
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 
63  // @Override
64 // protected Node copyNode(Node arg0) {
65  // return new ThumbnailViewNode(arg0);
66 // }
67  @Override
68  protected void addNotify() {
69  super.addNotify();
70 
71  setupKeys();
72  }
73 
74  int getTotalPages() {
75  return totalPages;
76  }
77 
78  int getTotalImages() {
79  return totalImages;
80  }
81 
82  private void setupKeys() {
83  //divide the supported content into buckets
84  totalImages = 0;
85  //TODO when lazy loading of original nodes is fixed
86  //we should be asking the datamodel for the children instead
87  //and not counting the children nodes (which might not be preloaded at this point)
88  final List<Node> suppContent = new ArrayList<Node>();
89  for (Node child : parent.getChildren().getNodes()) {
90  if (isSupported(child)) {
91  ++totalImages;
92  //Content content = child.getLookup().lookup(Content.class);
93  //suppContent.add(content);
94  suppContent.add(child);
95  }
96  }
97 
98  if (totalImages == 0) {
99  return;
100  }
101 
102  totalPages = 0;
103  if (totalImages < IMAGES_PER_PAGE) {
104  totalPages = 1;
105  } else {
106  totalPages = totalImages / IMAGES_PER_PAGE;
107  if (totalPages % totalImages != 0) {
108  ++totalPages;
109  }
110  }
111 
112  int prevImages = 0;
113  for (int page = 1; page <= totalPages; ++page) {
114  int toAdd = Math.min(IMAGES_PER_PAGE, totalImages - prevImages);
115  List<Node> pageContent = suppContent.subList(prevImages, prevImages + toAdd);
116  pages.put(page, pageContent);
117  prevImages += toAdd;
118  }
119 
120  Integer[] pageNums = new Integer[totalPages];
121  for (int i = 0; i < totalPages; ++i) {
122  pageNums[i] = i + 1;
123  }
124  setKeys(pageNums);
125 
126 
127  }
128 
129  @Override
130  protected void removeNotify() {
131  super.removeNotify();
132  pages.clear();
133  totalImages = 0;
134  }
135 
136  @Override
137  protected Node[] createNodes(Integer pageNum) {
138  final ThumbnailPageNode pageNode = new ThumbnailPageNode(pageNum);
139  return new Node[]{pageNode};
140  }
141 
142  public static boolean isSupported(Node node) {
143  if (node != null) {
144  Content content = node.getLookup().lookup(Content.class);
145  if (content != null) {
146  return ImageUtils.thumbnailSupported(content);
147  }
148  }
149  return false;
150  }
151 
152  public void setIconSize(int iconSize) {
153  this.iconSize = iconSize;
154  }
155 
160  private class ThumbnailPageNode extends AbstractNode {
161 
162  ThumbnailPageNode(Integer pageNum) {
163  super(new ThumbnailPageNodeChildren(pages.get(pageNum)), Lookups.singleton(pageNum));
164  setName(Integer.toString(pageNum));
165  int from = 1 + ((pageNum - 1) * IMAGES_PER_PAGE);
166  int showImages = Math.min(IMAGES_PER_PAGE, totalImages - (from - 1));
167  int to = from + showImages - 1;
168  setDisplayName(from + "-" + to);
169 
170  this.setIconBaseWithExtension("org/sleuthkit/autopsy/images/Folder-icon.png"); //NON-NLS
171 
172  }
173  }
174 
175  //TODO insert node at beginning pressing which goes back to page view
176  private class ThumbnailPageNodeChildren extends Children.Keys<Node> {
177 
178  //wrapped original nodes
179  private List<Node> contentImages = null;
180 
181  ThumbnailPageNodeChildren(List<Node> contentImages) {
182  super(true);
183 
184  this.contentImages = contentImages;
185  }
186 
187  @Override
188  protected void addNotify() {
189  super.addNotify();
190 
191  setKeys(contentImages);
192  }
193 
194  @Override
195  protected void removeNotify() {
196  super.removeNotify();
197 
198  setKeys(new ArrayList<Node>());
199  }
200 
201  @Override
202  protected Node[] createNodes(Node wrapped) {
203  if (wrapped != null) {
204  final ThumbnailViewNode thumb = new ThumbnailViewNode(wrapped, iconSize);
205  return new Node[]{thumb};
206  } else {
207  return new Node[]{};
208  }
209  }
210  }
211 }

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