Merge branch 'documentation/JAL-3111_release_211' into bug/JAL-2830_editManglesDatase...
[jalview.git] / getdown / src / getdown / launcher / src / main / java / com / threerings / getdown / launcher / AbortPanel.java
diff --git a/getdown/src/getdown/launcher/src/main/java/com/threerings/getdown/launcher/AbortPanel.java b/getdown/src/getdown/launcher/src/main/java/com/threerings/getdown/launcher/AbortPanel.java
new file mode 100644 (file)
index 0000000..dc1e54e
--- /dev/null
@@ -0,0 +1,100 @@
+//
+// Getdown - application installer, patcher and launcher
+// Copyright (C) 2004-2018 Getdown authors
+// https://github.com/threerings/getdown/blob/master/LICENSE
+
+package com.threerings.getdown.launcher;
+
+import java.awt.Dimension;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+import javax.swing.BorderFactory;
+import javax.swing.JButton;
+import javax.swing.JFrame;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+
+import com.samskivert.swing.GroupLayout;
+import com.samskivert.swing.Spacer;
+import com.samskivert.swing.VGroupLayout;
+
+import com.threerings.getdown.util.MessageUtil;
+import static com.threerings.getdown.Log.log;
+
+/**
+ * Displays a confirmation that the user wants to abort installation.
+ */
+public final class AbortPanel extends JFrame
+    implements ActionListener
+{
+    public AbortPanel (Getdown getdown, ResourceBundle msgs)
+    {
+        _getdown = getdown;
+        _msgs = msgs;
+
+        setLayout(new VGroupLayout());
+        setResizable(false);
+        setTitle(get("m.abort_title"));
+
+        JLabel message = new JLabel(get("m.abort_confirm"));
+        message.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
+        add(message);
+        add(new Spacer(5, 5));
+
+        JPanel row = GroupLayout.makeButtonBox(GroupLayout.CENTER);
+        JButton button;
+        row.add(button = new JButton(get("m.abort_ok")));
+        button.setActionCommand("ok");
+        button.addActionListener(this);
+        row.add(button = new JButton(get("m.abort_cancel")));
+        button.setActionCommand("cancel");
+        button.addActionListener(this);
+        getRootPane().setDefaultButton(button);
+        add(row);
+    }
+
+    // documentation inherited
+    @Override
+    public Dimension getPreferredSize ()
+    {
+        // this is annoyingly hardcoded, but we can't just force the width
+        // or the JLabel will claim a bogus height thinking it can lay its
+        // text out all on one line which will booch the whole UI's
+        // preferred size
+        return new Dimension(300, 200);
+    }
+
+    // documentation inherited from interface
+    public void actionPerformed (ActionEvent e)
+    {
+        String cmd = e.getActionCommand();
+        if (cmd.equals("ok")) {
+            System.exit(0);
+        } else {
+            setVisible(false);
+        }
+    }
+
+    /** Used to look up localized messages. */
+    protected String get (String key)
+    {
+        // if this string is tainted, we don't translate it, instead we
+        // simply remove the taint character and return it to the caller
+        if (MessageUtil.isTainted(key)) {
+            return MessageUtil.untaint(key);
+        }
+        try {
+            return _msgs.getString(key);
+        } catch (MissingResourceException mre) {
+            log.warning("Missing translation message '" + key + "'.");
+            return key;
+        }
+    }
+
+    protected Getdown _getdown;
+    protected ResourceBundle _msgs;
+}