Autopsy  4.4
Graphical digital forensics platform for The Sleuth Kit and other tools.
TypeFilter.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2013-16 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.timeline.filters;
20 
21 import java.util.Comparator;
22 import java.util.Objects;
23 import java.util.function.Predicate;
24 import javafx.collections.FXCollections;
25 import javafx.scene.image.Image;
26 import javafx.scene.paint.Color;
27 import org.openide.util.NbBundle;
30 
35 public class TypeFilter extends UnionFilter<TypeFilter> {
36 
37  static private final Comparator<TypeFilter> comparator = Comparator.comparing(TypeFilter::getEventType, EventType.getComparator());
38 
42  private final EventType eventType;
43 
52  private TypeFilter(EventType et, boolean recursive) {
53  super(FXCollections.observableArrayList());
54  this.eventType = et;
55 
56  if (recursive) { // add subfilters for each subtype
57  for (EventType subType : et.getSubTypes()) {
58  addSubFilter(new TypeFilter(subType), comparator);
59  }
60  }
61  }
62 
69  public TypeFilter(EventType et) {
70  this(et, true);
71  }
72 
74  return eventType;
75  }
76 
77  @Override
78  @NbBundle.Messages("TypeFilter.displayName.text=Event Type")
79  public String getDisplayName() {
80  return (eventType == RootEventType.getInstance())
81  ? Bundle.TypeFilter_displayName_text()
82  : eventType.getDisplayName();
83  }
84 
88  public Color getColor() {
89  return eventType.getColor();
90  }
91 
95  public Image getFXImage() {
96  return eventType.getFXImage();
97  }
98 
99  @Override
100  public TypeFilter copyOf() {
101  //make a nonrecursive copy of this filter
102  final TypeFilter filterCopy = new TypeFilter(eventType, false);
103  //add a copy of each subfilter
104  getSubFilters().forEach(typeFilter -> filterCopy.addSubFilter(typeFilter.copyOf(), comparator));
105  //these need to happen after the listeners fired by adding the subfilters
106  filterCopy.setSelected(isSelected());
107  filterCopy.setDisabled(isDisabled());
108  return filterCopy;
109  }
110 
111  @Override
112  public boolean equals(Object obj) {
113  if (obj == null) {
114  return false;
115  }
116  if (getClass() != obj.getClass()) {
117  return false;
118  }
119  final TypeFilter other = (TypeFilter) obj;
120 
121  if (isActive() != other.isActive()) {
122  return false;
123  }
124 
125  if (this.eventType != other.eventType) {
126  return false;
127  }
128  return areSubFiltersEqual(this, other);
129  }
130 
131  @Override
132  public int hashCode() {
133  int hash = 7;
134  hash = 67 * hash + Objects.hashCode(this.eventType);
135  return hash;
136  }
137 
138  @Override
139  Predicate<TypeFilter> getDuplicatePredicate(TypeFilter subfilter) {
140  return t -> subfilter.getEventType().equals(t.eventType);
141  }
142 }
TypeFilter(EventType et, boolean recursive)
Definition: TypeFilter.java:52
static final Comparator< TypeFilter > comparator
Definition: TypeFilter.java:37

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