From cc629ef1962a44a55b1655b9f8275789d3f9acbd Mon Sep 17 00:00:00 2001 From: Greg DiCristofaro Date: Tue, 16 Feb 2021 10:25:47 -0500 Subject: [PATCH] beginnings of wizard select host --- .../datamodel/hosts/SelectHostPanel.form | 119 +++++++++++++ .../datamodel/hosts/SelectHostPanel.java | 159 ++++++++++++++++++ 2 files changed, 278 insertions(+) create mode 100644 Core/src/org/sleuthkit/autopsy/datamodel/hosts/SelectHostPanel.form create mode 100644 Core/src/org/sleuthkit/autopsy/datamodel/hosts/SelectHostPanel.java diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/hosts/SelectHostPanel.form b/Core/src/org/sleuthkit/autopsy/datamodel/hosts/SelectHostPanel.form new file mode 100644 index 0000000000..ef94dbc5e2 --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/datamodel/hosts/SelectHostPanel.form @@ -0,0 +1,119 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/Core/src/org/sleuthkit/autopsy/datamodel/hosts/SelectHostPanel.java b/Core/src/org/sleuthkit/autopsy/datamodel/hosts/SelectHostPanel.java new file mode 100644 index 0000000000..672782ab3c --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/datamodel/hosts/SelectHostPanel.java @@ -0,0 +1,159 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package org.sleuthkit.autopsy.datamodel.hosts; + +import java.awt.Dialog; +import javax.swing.SwingUtilities; +import org.openide.util.NbBundle.Messages; +import org.sleuthkit.datamodel.Host; + +/** + * + * @author gregd + */ +public class SelectHostPanel extends javax.swing.JPanel { + + @Messages({ + "SelectHostPanel_HostCbItem_defaultHost=Default" + }) + private static class HostCbItem { + + private final Host host; + + public HostCbItem(Host host) { + this.host = host; + } + + public Host getHost() { + return host; + } + + @Override + public String toString() { + if (host == null) { + return Bundle.SelectHostPanel_HostCbItem_defaultHost(); + } else if (host.getName() == null) { + return ""; + } else { + return host.getName(); + } + } + } + + /** + * Creates new form SelectHostPanel + */ + public SelectHostPanel() { + initComponents(); + this.comboBoxHostName.addItem(new HostCbItem(null)); + } + + public Host getSelectedHost() { + return comboBoxHostName.getSelectedItem() instanceof HostCbItem + ? ((HostCbItem) comboBoxHostName.getSelectedItem()).getHost() + : null; + } + + /** + * This method is called from within the constructor to initialize the form. + * WARNING: Do NOT modify this code. The content of this method is always + * regenerated by the Form Editor. + */ + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + java.awt.GridBagConstraints gridBagConstraints; + + javax.swing.JLabel lbHostNameLabel = new javax.swing.JLabel(); + comboBoxHostName = new javax.swing.JComboBox<>(); + javax.swing.JButton bnManageHosts = new javax.swing.JButton(); + + setBorder(javax.swing.BorderFactory.createTitledBorder(org.openide.util.NbBundle.getMessage(SelectHostPanel.class, "SelectHostPanel.title"))); // NOI18N + + org.openide.awt.Mnemonics.setLocalizedText(lbHostNameLabel, org.openide.util.NbBundle.getMessage(SelectHostPanel.class, "SelectHostPanel.lbHostNameLabel.text")); // NOI18N + lbHostNameLabel.setMaximumSize(new java.awt.Dimension(300, 14)); + lbHostNameLabel.setMinimumSize(new java.awt.Dimension(189, 14)); + lbHostNameLabel.setPreferredSize(new java.awt.Dimension(220, 14)); + + comboBoxHostName.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + comboBoxHostNameActionPerformed(evt); + } + }); + + org.openide.awt.Mnemonics.setLocalizedText(bnManageHosts, org.openide.util.NbBundle.getMessage(SelectHostPanel.class, "SelectHostPanel.bnManageHosts.text")); // NOI18N + bnManageHosts.setMargin(new java.awt.Insets(2, 6, 2, 6)); + bnManageHosts.setMaximumSize(new java.awt.Dimension(160, 23)); + bnManageHosts.setMinimumSize(new java.awt.Dimension(123, 23)); + bnManageHosts.setPreferredSize(new java.awt.Dimension(140, 23)); + bnManageHosts.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + bnManageHostsActionPerformed(evt); + } + }); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); + this.setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addComponent(lbHostNameLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(18, 18, 18) + .addComponent(comboBoxHostName, 0, 180, Short.MAX_VALUE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(bnManageHosts, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap()) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(layout.createSequentialGroup() + .addContainerGap() + .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(comboBoxHostName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(bnManageHosts, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(lbHostNameLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + ); + + getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(SelectHostPanel.class, "SelectHostPanel.title")); // NOI18N + }// //GEN-END:initComponents + + private void comboBoxHostNameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboBoxHostNameActionPerformed +// @SuppressWarnings("unchecked") +// JComboBox cb = (JComboBox) evt.getSource(); +// String orgName = (String) cb.getSelectedItem(); +// if (null == orgName) { +// return; +// } +// if ("".equals(orgName)) { +// clearOrganization(); +// return; +// } +// for (CentralRepoOrganization org : orgs) { +// if (org.getName().equals(orgName)) { +// selectedOrg = org; +// lbPointOfContactNameText.setText(selectedOrg.getPocName()); +// lbPointOfContactEmailText.setText(selectedOrg.getPocEmail()); +// lbPointOfContactPhoneText.setText(selectedOrg.getPocPhone()); +// return; +// } +// } + }//GEN-LAST:event_comboBoxHostNameActionPerformed + + private void bnManageHostsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bnManageHostsActionPerformed + ManageHostsDialog dialog = new ManageHostsDialog((Dialog) SwingUtilities.getWindowAncestor(this)); + loadHostData(); + if (dialog.getSelectedHost() != null) { + setSelectedHost(dialog.getSelectedHost()); + } + }//GEN-LAST:event_bnManageHostsActionPerformed + + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JComboBox comboBoxHostName; + // End of variables declaration//GEN-END:variables +}