Autopsy  4.20.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
CTLicenseDialog.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2023 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 com.basistech.df.cybertriage.autopsy.ctoptions.ctcloud;
20 
21 import java.util.regex.Pattern;
22 import javax.swing.event.DocumentEvent;
23 import javax.swing.event.DocumentListener;
24 import org.apache.commons.lang3.StringUtils;
25 import org.openide.util.NbBundle.Messages;
26 
30 public class CTLicenseDialog extends javax.swing.JDialog {
31 
32  private static final Pattern LICENSE_PATTERN = Pattern.compile("^\\s*[a-zA-Z0-9\\-]+?\\s*$");
33  private String licenseString = null;
34 
38  public CTLicenseDialog(java.awt.Frame parent, boolean modal) {
39  super(parent, modal);
41  this.licenseNumberTextField.getDocument().putProperty("filterNewlines", Boolean.TRUE);
42  this.licenseNumberTextField.getDocument().addDocumentListener(new DocumentListener() {
43  @Override
44  public void changedUpdate(DocumentEvent e) {
45  verifyInput();
46  }
47 
48  @Override
49  public void insertUpdate(DocumentEvent e) {
50  verifyInput();
51  }
52 
53  @Override
54  public void removeUpdate(DocumentEvent e) {
55  verifyInput();
56  }
57  });
58  }
59 
60  String getValue() {
61  return licenseString;
62  }
63 
64  @Messages({
65  "CTLicenseDialog_verifyInput_licenseNumberError=<html>Please verify license number format of 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX'</html>"
66  })
67  private void verifyInput() {
68  String licenseInput = StringUtils.defaultString(this.licenseNumberTextField.getText());
69  if (LICENSE_PATTERN.matcher(licenseInput).matches()) {
70  this.warningLabel.setText("");
71  this.okButton.setEnabled(true);
72  } else {
73  this.warningLabel.setText(Bundle.CTLicenseDialog_verifyInput_licenseNumberError());
74  this.okButton.setEnabled(false);
75  }
76  }
77 
83  @SuppressWarnings("unchecked")
84  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
85  private void initComponents() {
86  java.awt.GridBagConstraints gridBagConstraints;
87 
88  javax.swing.JLabel licenseNumberLabel = new javax.swing.JLabel();
89  warningLabel = new javax.swing.JLabel();
90  javax.swing.JPanel buttonPadding = new javax.swing.JPanel();
91  okButton = new javax.swing.JButton();
92  cancelButton = new javax.swing.JButton();
93  licenseNumberTextField = new javax.swing.JTextField();
94 
95  setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
96  setTitle(org.openide.util.NbBundle.getMessage(CTLicenseDialog.class, "CTLicenseDialog.title")); // NOI18N
97  setAlwaysOnTop(true);
98  setResizable(false);
99  getContentPane().setLayout(new java.awt.GridBagLayout());
100 
101  org.openide.awt.Mnemonics.setLocalizedText(licenseNumberLabel, org.openide.util.NbBundle.getMessage(CTLicenseDialog.class, "CTLicenseDialog.licenseNumberLabel.text")); // NOI18N
102  gridBagConstraints = new java.awt.GridBagConstraints();
103  gridBagConstraints.gridx = 0;
104  gridBagConstraints.gridy = 0;
105  gridBagConstraints.gridwidth = 3;
106  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
107  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
108  gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
109  getContentPane().add(licenseNumberLabel, gridBagConstraints);
110 
111  warningLabel.setForeground(java.awt.Color.RED);
112  org.openide.awt.Mnemonics.setLocalizedText(warningLabel, org.openide.util.NbBundle.getMessage(CTLicenseDialog.class, "CTLicenseDialog.warningLabel.text")); // NOI18N
113  warningLabel.setMaximumSize(new java.awt.Dimension(419, 36));
114  warningLabel.setMinimumSize(new java.awt.Dimension(419, 36));
115  warningLabel.setPreferredSize(new java.awt.Dimension(419, 36));
116  gridBagConstraints = new java.awt.GridBagConstraints();
117  gridBagConstraints.gridx = 0;
118  gridBagConstraints.gridy = 2;
119  gridBagConstraints.gridwidth = 3;
120  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
121  gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
122  getContentPane().add(warningLabel, gridBagConstraints);
123 
124  javax.swing.GroupLayout buttonPaddingLayout = new javax.swing.GroupLayout(buttonPadding);
125  buttonPadding.setLayout(buttonPaddingLayout);
126  buttonPaddingLayout.setHorizontalGroup(
127  buttonPaddingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
128  .addGap(0, 0, Short.MAX_VALUE)
129  );
130  buttonPaddingLayout.setVerticalGroup(
131  buttonPaddingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
132  .addGap(0, 0, Short.MAX_VALUE)
133  );
134 
135  gridBagConstraints = new java.awt.GridBagConstraints();
136  gridBagConstraints.gridx = 0;
137  gridBagConstraints.gridy = 3;
138  gridBagConstraints.weightx = 1.0;
139  getContentPane().add(buttonPadding, gridBagConstraints);
140 
141  org.openide.awt.Mnemonics.setLocalizedText(okButton, org.openide.util.NbBundle.getMessage(CTLicenseDialog.class, "CTLicenseDialog.okButton.text")); // NOI18N
142  okButton.addActionListener(new java.awt.event.ActionListener() {
143  public void actionPerformed(java.awt.event.ActionEvent evt) {
145  }
146  });
147  gridBagConstraints = new java.awt.GridBagConstraints();
148  gridBagConstraints.gridx = 2;
149  gridBagConstraints.gridy = 3;
150  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
151  gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
152  getContentPane().add(okButton, gridBagConstraints);
153 
154  org.openide.awt.Mnemonics.setLocalizedText(cancelButton, org.openide.util.NbBundle.getMessage(CTLicenseDialog.class, "CTLicenseDialog.cancelButton.text")); // NOI18N
155  cancelButton.addActionListener(new java.awt.event.ActionListener() {
156  public void actionPerformed(java.awt.event.ActionEvent evt) {
158  }
159  });
160  gridBagConstraints = new java.awt.GridBagConstraints();
161  gridBagConstraints.gridx = 1;
162  gridBagConstraints.gridy = 3;
163  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
164  gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
165  getContentPane().add(cancelButton, gridBagConstraints);
166 
167  licenseNumberTextField.setText(org.openide.util.NbBundle.getMessage(CTLicenseDialog.class, "CTLicenseDialog.licenseNumberTextField.text")); // NOI18N
168  gridBagConstraints = new java.awt.GridBagConstraints();
169  gridBagConstraints.gridx = 0;
170  gridBagConstraints.gridy = 1;
171  gridBagConstraints.gridwidth = 3;
172  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
173  gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
174  getContentPane().add(licenseNumberTextField, gridBagConstraints);
175 
176  pack();
177  }// </editor-fold>//GEN-END:initComponents
178 
179  private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
180  this.licenseString = this.licenseNumberTextField.getText();
181  this.dispose();
182  }//GEN-LAST:event_okButtonActionPerformed
183 
184  private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
185  this.licenseString = null;
186  this.dispose();
187  }//GEN-LAST:event_cancelButtonActionPerformed
188 
189 
190  // Variables declaration - do not modify//GEN-BEGIN:variables
191  private javax.swing.JButton cancelButton;
192  private javax.swing.JTextField licenseNumberTextField;
193  private javax.swing.JButton okButton;
194  private javax.swing.JLabel warningLabel;
195  // End of variables declaration//GEN-END:variables
196 }

Copyright © 2012-2022 Basis Technology. Generated on: Tue Aug 1 2023
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.