aboutsummaryrefslogtreecommitdiff
path: root/src/main/ui/widgets/CertEditDialog.java
diff options
context:
space:
mode:
authorYuuta Liang <yuutaw@student.cs.ubc.ca>2023-11-28 18:19:39 -0800
committerYuuta Liang <yuutaw@student.cs.ubc.ca>2023-11-28 18:19:39 -0800
commit1073af21305360bd33903c533cdac57e9f936294 (patch)
tree2c2d9c343ffe2577286fb53e016f06f6cdc53cbf /src/main/ui/widgets/CertEditDialog.java
parente13adbb9a9146dd5ece890449e3cad958a502f86 (diff)
downloadjca-1073af21305360bd33903c533cdac57e9f936294.tar
jca-1073af21305360bd33903c533cdac57e9f936294.tar.gz
jca-1073af21305360bd33903c533cdac57e9f936294.tar.bz2
jca-1073af21305360bd33903c533cdac57e9f936294.zip
Move TUI and GUI into separate packages
Signed-off-by: Yuuta Liang <yuutaw@student.cs.ubc.ca>
Diffstat (limited to 'src/main/ui/widgets/CertEditDialog.java')
-rw-r--r--src/main/ui/widgets/CertEditDialog.java108
1 files changed, 0 insertions, 108 deletions
diff --git a/src/main/ui/widgets/CertEditDialog.java b/src/main/ui/widgets/CertEditDialog.java
deleted file mode 100644
index bad5a4f..0000000
--- a/src/main/ui/widgets/CertEditDialog.java
+++ /dev/null
@@ -1,108 +0,0 @@
-package ui.widgets;
-
-import javax.swing.*;
-import java.awt.*;
-import java.awt.event.ActionEvent;
-import java.awt.event.KeyEvent;
-import java.awt.event.WindowAdapter;
-import java.awt.event.WindowEvent;
-
-import static java.awt.GridBagConstraints.HORIZONTAL;
-import static java.awt.GridBagConstraints.WEST;
-import static ui.widgets.UIUtils.btn;
-
-/**
- * A common dialog for cert / template editing. It will close upon Esc or Cancel.
- * +---------------------------++---------------------------++---------------------------+
- * | Dialog X || New Template X || Issue new certificate X |
- * | || || |
- * |Template: (TBD) ||Template: _________||Template: (Drop down)|
- * |Subject: _________||Subject: _________||Subject: _________ |
- * |Validity (Days): (Spinner)||Validity (Days): (Spinner)||Validity (Days): (Spinner)|
- * | || || |
- * | Button Cancel|| Add Cancel|| Issue Cancel|
- * +---------------------------++---------------------------++---------------------------+
- */
-public abstract class CertEditDialog<T> extends JDialog {
- /**
- * The result.
- */
- protected T res;
-
- /**
- * Root pane.
- */
- protected JPanel contentPane = new JPanel();
- protected JButton buttonOK = btn("", this::onOK);
- protected JTextField textFieldSubject = new JTextField();
- protected JSpinner spinnerValidity =
- new JSpinner(new SpinnerNumberModel(60, 1, null, 0));
-
- /**
- * EFFECTS: Render the dialog, leaving title and OK button text blank.
- */
- public CertEditDialog() {
- contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS));
- contentPane.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8));
- contentPane.add(renderForm());
-
- contentPane.add(UIUtils.createActionsPane(buttonOK, btn("Cancel", this::onCancel)));
-
- setContentPane(contentPane);
- setModal(true);
- getRootPane().setDefaultButton(buttonOK);
- setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
-
- addWindowListener(new WindowAdapter() {
- public void windowClosing(WindowEvent e) {
- onCancel(null);
- }
- });
-
- contentPane.registerKeyboardAction(this::onCancel,
- KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
- JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
- }
-
- /**
- * EFFECTS: Render the form.
- */
- private JPanel renderForm() {
- final JPanel panelForm = new JPanel(new GridBagLayout());
- panelForm.add(new JLabel("Template: "), new GCBuilder().anchor(WEST).build());
- panelForm.add(new JLabel("Subject: "), new GCBuilder().gridY(1).anchor(WEST).build());
- panelForm.add(new JLabel("Validity (Days): "), new GCBuilder().gridY(2).anchor(WEST).build());
- panelForm.add(createTemplateComponent(), new GCBuilder().gridXY(1, 0).anchor(WEST)
- .fill(HORIZONTAL).build());
- panelForm.add(textFieldSubject, new GCBuilder().gridXY(1, 1).anchor(WEST).fill(HORIZONTAL).build());
- panelForm.add(spinnerValidity, new GCBuilder().gridXY(1, 2).anchor(WEST).fill(HORIZONTAL).build());
- panelForm.add(new JPanel(), new GCBuilder().gridXY(1, 3).expandXY().fill(HORIZONTAL).build());
- return panelForm;
- }
-
- /**
- * EFFECTS: Create the component for subject.
- */
- protected abstract JComponent createTemplateComponent();
-
- /**
- * EFFECTS: Handle OK.
- */
- protected abstract void onOK(ActionEvent ev);
-
- /**
- * EFFECTS: Handle cancel: clear result and close dialog.
- * MODIFIES: this
- */
- private void onCancel(ActionEvent ev) {
- res = null;
- dispose();
- }
-
- /**
- * EFFECTS: Get the result.
- */
- public T getRes() {
- return res;
- }
-}