Autopsy 4.22.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 */
19package org.sleuthkit.autopsy.datasourcesummary.uiutils;
20
21import java.util.ArrayList;
22import java.util.Collections;
23import java.util.List;
24import java.util.function.Function;
25import java.util.function.Supplier;
26
30public 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
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
89 this.tooltip = tooltip;
90 return this;
91 }
92
93 @Override
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
129 this.menuItemSupplier = menuItemSupplier;
130 return this;
131 }
132
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 > setHorizontalAlignment(CellModel.HorizontalAlign alignment)
DefaultCellModel< T > setPopupMenuRetriever(Supplier< List< MenuItem > > menuItemSupplier)
DefaultCellModel< T > setPopupMenu(List< MenuItem > popupMenu)
DefaultCellModel(T data, Function< T, String > stringConverter)

Copyright © 2012-2024 Sleuth Kit Labs. Generated on:
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.