Autopsy  4.19.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
DefaultCellModel.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2021 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.datasourcesummary.uiutils;
20 
21 import java.util.ArrayList;
22 import java.util.Collections;
23 import java.util.List;
24 import java.util.function.Function;
25 import java.util.function.Supplier;
26 
30 public class DefaultCellModel<T> implements GuiCellModel {
31 
32  private final T data;
33  private final String text;
34  private String tooltip;
36  private List<MenuItem> popupMenu;
37  private Supplier<List<MenuItem>> menuItemSupplier;
38 
44  public DefaultCellModel(T data) {
45  this(data, null);
46  }
47 
55  public DefaultCellModel(T data, Function<T, String> stringConverter) {
56  this.data = data;
57 
58  if (stringConverter == null) {
59  text = this.data == null ? "" : this.data.toString();
60  } else {
61  text = stringConverter.apply(this.data);
62  }
63  this.tooltip = text;
64  }
65 
66  @Override
67  public T getData() {
68  return this.data;
69  }
70 
71  @Override
72  public String getText() {
73  return text;
74  }
75 
76  @Override
77  public String getTooltip() {
78  return tooltip;
79  }
80 
88  public DefaultCellModel<T> setTooltip(String tooltip) {
89  this.tooltip = tooltip;
90  return this;
91  }
92 
93  @Override
95  return horizontalAlignment;
96  }
97 
106  this.horizontalAlignment = alignment;
107  return this;
108  }
109 
110  @Override
111  public List<MenuItem> getPopupMenu() {
112  if (popupMenu != null) {
113  return Collections.unmodifiableList(popupMenu);
114  }
115  if (menuItemSupplier != null) {
116  return this.menuItemSupplier.get();
117  }
118  return null;
119  }
120 
128  public DefaultCellModel<T> setPopupMenuRetriever(Supplier<List<MenuItem>> menuItemSupplier) {
129  this.menuItemSupplier = menuItemSupplier;
130  return this;
131  }
132 
140  public DefaultCellModel<T> setPopupMenu(List<MenuItem> popupMenu) {
141  this.popupMenu = popupMenu == null ? null : new ArrayList<>(popupMenu);
142  return this;
143  }
144 
145  @Override
146  public String toString() {
147  return getText();
148  }
149 }
DefaultCellModel< T > setPopupMenuRetriever(Supplier< List< MenuItem >> menuItemSupplier)
DefaultCellModel(T data, Function< T, String > stringConverter)
DefaultCellModel< T > setHorizontalAlignment(CellModel.HorizontalAlign alignment)
DefaultCellModel< T > setPopupMenu(List< MenuItem > popupMenu)

Copyright © 2012-2021 Basis Technology. Generated on: Thu Sep 30 2021
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.