Autopsy  4.21.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.awt.Color;
22 import java.util.regex.Pattern;
23 import javax.swing.event.DocumentEvent;
24 import javax.swing.event.DocumentListener;
25 import org.apache.commons.lang3.StringUtils;
26 import org.openide.util.NbBundle.Messages;
28 
32 class CTLicenseDialog extends javax.swing.JDialog {
33 
34  private static final Pattern LICENSE_PATTERN = Pattern.compile("^\\s*[a-zA-Z0-9-_]+?\\s*$");
35  private String licenseString = null;
36 
40  public CTLicenseDialog(java.awt.Frame parent, boolean modal) {
41  super(parent, modal);
42  initComponents();
43  configureHintText();
44  this.licenseNumberTextField.getDocument().putProperty("filterNewlines", Boolean.TRUE);
45  this.licenseNumberTextField.getDocument().addDocumentListener(new DocumentListener() {
46  @Override
47  public void changedUpdate(DocumentEvent e) {
48  verifyInput();
49  }
50 
51  @Override
52  public void insertUpdate(DocumentEvent e) {
53  verifyInput();
54  }
55 
56  @Override
57  public void removeUpdate(DocumentEvent e) {
58  verifyInput();
59  }
60  });
61 
62  // set ok button as primary button
63  this.getRootPane().setDefaultButton(okButton);
64  // request focus for entering license string
65  this.licenseNumberTextField.requestFocusInWindow();
66  }
67 
68  private void configureHintText() {
69  TextPrompt textPrompt = new TextPrompt(
70  StringUtils.defaultString(this.licenseNumberTextField.getToolTipText()),
71  this.licenseNumberTextField);
72 
73  textPrompt.setForeground(Color.LIGHT_GRAY);
74  float alpha = 0.9f; // Mostly opaque
75  textPrompt.changeAlpha(alpha);
76  }
77 
78  String getValue() {
79  return licenseString;
80  }
81 
82  @Messages({
83  "CTLicenseDialog_verifyInput_licenseNumberError=<html>Please enter a license number</html>"
84  })
85  private void verifyInput() {
86  String licenseInput = StringUtils.defaultString(this.licenseNumberTextField.getText());
87  if (LICENSE_PATTERN.matcher(licenseInput).matches()) {
88  this.warningLabel.setText("");
89  this.okButton.setEnabled(true);
90  } else {
91  this.warningLabel.setText(Bundle.CTLicenseDialog_verifyInput_licenseNumberError());
92  this.okButton.setEnabled(false);
93  }
94  }
95 
101  @SuppressWarnings("unchecked")
102  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
103  private void initComponents() {
104  java.awt.GridBagConstraints gridBagConstraints;
105 
106  javax.swing.JLabel licenseNumberLabel = new javax.swing.JLabel();
107  licenseNumberTextField = new javax.swing.JTextField();
108  warningLabel = new javax.swing.JLabel();
109  javax.swing.JPanel buttonPadding = new javax.swing.JPanel();
110  javax.swing.JPanel buttonPanel = new javax.swing.JPanel();
111  okButton = new javax.swing.JButton();
112  cancelButton = new javax.swing.JButton();
113 
114  setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
115  setTitle(org.openide.util.NbBundle.getMessage(CTLicenseDialog.class, "CTLicenseDialog.title")); // NOI18N
116  setAlwaysOnTop(true);
117  setResizable(false);
118  getContentPane().setLayout(new java.awt.GridBagLayout());
119 
120  org.openide.awt.Mnemonics.setLocalizedText(licenseNumberLabel, org.openide.util.NbBundle.getMessage(CTLicenseDialog.class, "CTLicenseDialog.licenseNumberLabel.text")); // NOI18N
121  gridBagConstraints = new java.awt.GridBagConstraints();
122  gridBagConstraints.gridx = 0;
123  gridBagConstraints.gridy = 0;
124  gridBagConstraints.gridwidth = 3;
125  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
126  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
127  gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
128  getContentPane().add(licenseNumberLabel, gridBagConstraints);
129 
130  licenseNumberTextField.setText(org.openide.util.NbBundle.getMessage(CTLicenseDialog.class, "CTLicenseDialog.licenseNumberTextField.text")); // NOI18N
131  licenseNumberTextField.setToolTipText(org.openide.util.NbBundle.getMessage(CTLicenseDialog.class, "CTLicenseDialog.licenseNumberTextField.toolTipText")); // NOI18N
132  gridBagConstraints = new java.awt.GridBagConstraints();
133  gridBagConstraints.gridx = 0;
134  gridBagConstraints.gridy = 1;
135  gridBagConstraints.gridwidth = 3;
136  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
137  gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
138  getContentPane().add(licenseNumberTextField, gridBagConstraints);
139 
140  warningLabel.setForeground(java.awt.Color.RED);
141  org.openide.awt.Mnemonics.setLocalizedText(warningLabel, org.openide.util.NbBundle.getMessage(CTLicenseDialog.class, "CTLicenseDialog.warningLabel.text")); // NOI18N
142  warningLabel.setMaximumSize(new java.awt.Dimension(419, 36));
143  warningLabel.setMinimumSize(new java.awt.Dimension(419, 36));
144  warningLabel.setPreferredSize(new java.awt.Dimension(419, 36));
145  gridBagConstraints = new java.awt.GridBagConstraints();
146  gridBagConstraints.gridx = 0;
147  gridBagConstraints.gridy = 2;
148  gridBagConstraints.gridwidth = 3;
149  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
150  gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 5);
151  getContentPane().add(warningLabel, gridBagConstraints);
152 
153  javax.swing.GroupLayout buttonPaddingLayout = new javax.swing.GroupLayout(buttonPadding);
154  buttonPadding.setLayout(buttonPaddingLayout);
155  buttonPaddingLayout.setHorizontalGroup(
156  buttonPaddingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
157  .addGap(0, 0, Short.MAX_VALUE)
158  );
159  buttonPaddingLayout.setVerticalGroup(
160  buttonPaddingLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
161  .addGap(0, 0, Short.MAX_VALUE)
162  );
163 
164  gridBagConstraints = new java.awt.GridBagConstraints();
165  gridBagConstraints.gridx = 0;
166  gridBagConstraints.gridy = 3;
167  gridBagConstraints.weightx = 1.0;
168  getContentPane().add(buttonPadding, gridBagConstraints);
169 
170  buttonPanel.setLayout(new java.awt.GridBagLayout());
171 
172  org.openide.awt.Mnemonics.setLocalizedText(okButton, org.openide.util.NbBundle.getMessage(CTLicenseDialog.class, "CTLicenseDialog.okButton.text")); // NOI18N
173  okButton.addActionListener(new java.awt.event.ActionListener() {
174  public void actionPerformed(java.awt.event.ActionEvent evt) {
175  okButtonActionPerformed(evt);
176  }
177  });
178  gridBagConstraints = new java.awt.GridBagConstraints();
179  gridBagConstraints.gridx = 0;
180  gridBagConstraints.gridy = 0;
181  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
182  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
183  gridBagConstraints.weightx = 1.0;
184  gridBagConstraints.insets = new java.awt.Insets(0, 5, 10, 5);
185  buttonPanel.add(okButton, gridBagConstraints);
186 
187  org.openide.awt.Mnemonics.setLocalizedText(cancelButton, org.openide.util.NbBundle.getMessage(CTLicenseDialog.class, "CTLicenseDialog.cancelButton.text")); // NOI18N
188  cancelButton.addActionListener(new java.awt.event.ActionListener() {
189  public void actionPerformed(java.awt.event.ActionEvent evt) {
190  cancelButtonActionPerformed(evt);
191  }
192  });
193  gridBagConstraints = new java.awt.GridBagConstraints();
194  gridBagConstraints.gridx = 1;
195  gridBagConstraints.gridy = 0;
196  gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
197  gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
198  gridBagConstraints.weightx = 1.0;
199  gridBagConstraints.insets = new java.awt.Insets(0, 0, 10, 10);
200  buttonPanel.add(cancelButton, gridBagConstraints);
201 
202  gridBagConstraints = new java.awt.GridBagConstraints();
203  gridBagConstraints.gridx = 1;
204  gridBagConstraints.gridy = 3;
205  gridBagConstraints.gridwidth = 2;
206  getContentPane().add(buttonPanel, gridBagConstraints);
207 
208  pack();
209  }// </editor-fold>//GEN-END:initComponents
210 
211  private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
212  String inputText = this.licenseNumberTextField.getText();
213  this.licenseString = inputText == null ? null : inputText.trim();
214  this.dispose();
215  }//GEN-LAST:event_okButtonActionPerformed
216 
217  private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelButtonActionPerformed
218  this.licenseString = null;
219  this.dispose();
220  }//GEN-LAST:event_cancelButtonActionPerformed
221 
222 
223  // Variables declaration - do not modify//GEN-BEGIN:variables
224  private javax.swing.JButton cancelButton;
225  private javax.swing.JTextField licenseNumberTextField;
226  private javax.swing.JButton okButton;
227  private javax.swing.JLabel warningLabel;
228  // End of variables declaration//GEN-END:variables
229 }

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