Autopsy 4.22.1
Graphical digital forensics platform for The Sleuth Kit and other tools.
CentralRepoCommentDialog.java
Go to the documentation of this file.
1/*
2 * Autopsy Forensic Browser
3 *
4 * Copyright 2018 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.centralrepository;
20
21import javax.swing.text.AbstractDocument;
22import org.openide.util.NbBundle.Messages;
23import org.openide.windows.WindowManager;
24import javax.swing.text.AttributeSet;
25import javax.swing.text.BadLocationException;
26import javax.swing.text.DocumentFilter;
27import org.sleuthkit.autopsy.centralrepository.datamodel.CorrelationAttributeInstance;
28
33@Messages({"CentralRepoCommentDialog.title.addEditCentralRepoComment=Add/Edit Central Repository Comment"})
34@SuppressWarnings("PMD.SingularField") // UI widgets cause lots of false positives
35final class CentralRepoCommentDialog extends javax.swing.JDialog {
36
37 private final CorrelationAttributeInstance correlationAttributeInstance;
38 private boolean commentUpdated = false;
39 private String currentComment = "";
40
47 CentralRepoCommentDialog(CorrelationAttributeInstance correlationAttributeInstance) {
48 super(WindowManager.getDefault().getMainWindow(), Bundle.CentralRepoCommentDialog_title_addEditCentralRepoComment());
49
50 initComponents();
51
52 CorrelationAttributeInstance instance = correlationAttributeInstance;
53
54 // Store the original comment
55 if (instance.getComment() != null) {
56 currentComment = instance.getComment();
57 }
58
59 //Truncate legacy comments to be MAX_CHARACTERS characters, pressing 'okay'
60 //once the editted comment is loaded in will truncate it in the database as
61 //well.
62 commentTextArea.setText(instance.getComment());
63
64 this.correlationAttributeInstance = correlationAttributeInstance;
65 }
66
70 void display() {
71 setModal(true);
72 setSize(getPreferredSize());
73 setLocationRelativeTo(this.getParent());
74 setAlwaysOnTop(false);
75 pack();
76 setVisible(true);
77 }
78
84 boolean isCommentUpdated() {
85 return commentUpdated;
86 }
87
94 String getComment() {
95 return currentComment;
96 }
97
102 private class CentralRepoCommentLengthFilter extends DocumentFilter {
103
104 private final Integer MAX_CHARACTERS = 500;
106
110
126 public void insertString(FilterBypass filter, int offset, String input,
127 AttributeSet attrSet) throws BadLocationException {
128 //Truncate the insert if its too long
129 this.replace(filter, offset, 0, input, attrSet);
130 }
131
145 public void remove(FilterBypass filter, int offset, int length)
146 throws BadLocationException {
147 super.remove(filter, offset, length);
148 remainingCharacters += length;
149 updateLabel();
150 }
151
168 public void replace(FilterBypass filter, int offset, int length, String input,
169 AttributeSet attrSet) throws BadLocationException {
170 //Truncate the replace if its too long
171 String truncatedText = input;
172 if ((filter.getDocument().getLength() + input.length() - length) > MAX_CHARACTERS) {
173 truncatedText = input.substring(0, MAX_CHARACTERS -
174 filter.getDocument().getLength() - length);
175 }
176 super.replace(filter, offset, length, truncatedText, attrSet);
177 remainingCharacters -= truncatedText.length() - length;
178 updateLabel();
179 }
180
186 private void updateLabel() {
187 if (remainingCharacters == 0) {
188 remainingCharactersLabel.setText(String.format(
189 "<html><font color=\"red\">%d</font> %s</html>",
190 remainingCharacters, "characters remaining"));
191 } else {
192 remainingCharactersLabel.setText(String.format(
193 "<html><font color=\"black\">%d</font> %s</html>",
194 remainingCharacters, "characters remaining"));
195 }
196 }
197 }
198
204 @SuppressWarnings("unchecked")
205 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
206 private void initComponents() {
207
208 jScrollPane1 = new javax.swing.JScrollPane();
209 commentTextArea = new javax.swing.JTextArea();
210 okButton = new javax.swing.JButton();
211 cancelButton = new javax.swing.JButton();
212 commentLabel = new javax.swing.JLabel();
213 remainingCharactersLabel = new javax.swing.JLabel();
214
215 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
216 setSize(getPreferredSize());
217
218 commentTextArea.setColumns(20);
219 commentTextArea.setLineWrap(true);
220 commentTextArea.setRows(5);
221 commentTextArea.setTabSize(4);
222 commentTextArea.setWrapStyleWord(true);
223 ((AbstractDocument)commentTextArea.getDocument())
224 .setDocumentFilter(new CentralRepoCommentLengthFilter());
225 jScrollPane1.setViewportView(commentTextArea);
226
227 org.openide.awt.Mnemonics.setLocalizedText(okButton, org.openide.util.NbBundle.getMessage(CentralRepoCommentDialog.class, "CentralRepoCommentDialog.okButton.text")); // NOI18N
228 okButton.addActionListener(new java.awt.event.ActionListener() {
229 public void actionPerformed(java.awt.event.ActionEvent evt) {
230 okButtonActionPerformed(evt);
231 }
232 });
233
234 org.openide.awt.Mnemonics.setLocalizedText(cancelButton, org.openide.util.NbBundle.getMessage(CentralRepoCommentDialog.class, "CentralRepoCommentDialog.cancelButton.text")); // NOI18N
235 cancelButton.addActionListener(new java.awt.event.ActionListener() {
236 public void actionPerformed(java.awt.event.ActionEvent evt) {
237 cancelButtonActionPerformed(evt);
238 }
239 });
240
241 org.openide.awt.Mnemonics.setLocalizedText(commentLabel, org.openide.util.NbBundle.getMessage(CentralRepoCommentDialog.class, "CentralRepoCommentDialog.commentLabel.text")); // NOI18N
242
243 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
244 getContentPane().setLayout(layout);
245 layout.setHorizontalGroup(
246 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
247 .addGroup(layout.createSequentialGroup()
248 .addContainerGap()
249 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
250 .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 500, Short.MAX_VALUE)
251 .addGroup(layout.createSequentialGroup()
252 .addComponent(commentLabel)
253 .addGap(0, 451, Short.MAX_VALUE))
254 .addGroup(layout.createSequentialGroup()
255 .addComponent(remainingCharactersLabel)
256 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
257 .addComponent(okButton, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)
258 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
259 .addComponent(cancelButton, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE)))
260 .addContainerGap())
261 );
262 layout.setVerticalGroup(
263 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
264 .addGroup(layout.createSequentialGroup()
265 .addContainerGap()
266 .addComponent(commentLabel)
267 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
268 .addComponent(jScrollPane1)
269 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
270 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
271 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
272 .addComponent(cancelButton)
273 .addComponent(okButton))
274 .addComponent(remainingCharactersLabel))
275 .addContainerGap())
276 );
277
278 pack();
279 }// </editor-fold>//GEN-END:initComponents
280
281 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
282 dispose();
283 }//GEN-LAST:event_cancelButtonActionPerformed
284
285 private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
286 currentComment = commentTextArea.getText();
287 correlationAttributeInstance.setComment(currentComment);
288 commentUpdated = true;
289
290 dispose();
291 }//GEN-LAST:event_okButtonActionPerformed
292
293 // Variables declaration - do not modify//GEN-BEGIN:variables
294 private javax.swing.JButton cancelButton;
295 private javax.swing.JLabel commentLabel;
296 private javax.swing.JTextArea commentTextArea;
297 private javax.swing.JLabel remainingCharactersLabel;
298 private javax.swing.JScrollPane jScrollPane1;
299 private javax.swing.JButton okButton;
300 // End of variables declaration//GEN-END:variables
301}
void insertString(FilterBypass filter, int offset, String input, AttributeSet attrSet)
void replace(FilterBypass filter, int offset, int length, String input, AttributeSet attrSet)

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