JAL-3130 adapted getdown src. attempt 2. first attempt failed due to cp'ed .git files
[jalview.git] / getdown / src / getdown / launcher / src / main / java / com / threerings / getdown / launcher / AbortPanel.java
1 //
2 // Getdown - application installer, patcher and launcher
3 // Copyright (C) 2004-2018 Getdown authors
4 // https://github.com/threerings/getdown/blob/master/LICENSE
5
6 package com.threerings.getdown.launcher;
7
8 import java.awt.Dimension;
9 import java.awt.event.ActionEvent;
10 import java.awt.event.ActionListener;
11
12 import java.util.MissingResourceException;
13 import java.util.ResourceBundle;
14
15 import javax.swing.BorderFactory;
16 import javax.swing.JButton;
17 import javax.swing.JFrame;
18 import javax.swing.JLabel;
19 import javax.swing.JPanel;
20
21 import com.samskivert.swing.GroupLayout;
22 import com.samskivert.swing.Spacer;
23 import com.samskivert.swing.VGroupLayout;
24
25 import com.threerings.getdown.util.MessageUtil;
26 import static com.threerings.getdown.Log.log;
27
28 /**
29  * Displays a confirmation that the user wants to abort installation.
30  */
31 public final class AbortPanel extends JFrame
32     implements ActionListener
33 {
34     public AbortPanel (Getdown getdown, ResourceBundle msgs)
35     {
36         _getdown = getdown;
37         _msgs = msgs;
38
39         setLayout(new VGroupLayout());
40         setResizable(false);
41         setTitle(get("m.abort_title"));
42
43         JLabel message = new JLabel(get("m.abort_confirm"));
44         message.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
45         add(message);
46         add(new Spacer(5, 5));
47
48         JPanel row = GroupLayout.makeButtonBox(GroupLayout.CENTER);
49         JButton button;
50         row.add(button = new JButton(get("m.abort_ok")));
51         button.setActionCommand("ok");
52         button.addActionListener(this);
53         row.add(button = new JButton(get("m.abort_cancel")));
54         button.setActionCommand("cancel");
55         button.addActionListener(this);
56         getRootPane().setDefaultButton(button);
57         add(row);
58     }
59
60     // documentation inherited
61     @Override
62     public Dimension getPreferredSize ()
63     {
64         // this is annoyingly hardcoded, but we can't just force the width
65         // or the JLabel will claim a bogus height thinking it can lay its
66         // text out all on one line which will booch the whole UI's
67         // preferred size
68         return new Dimension(300, 200);
69     }
70
71     // documentation inherited from interface
72     public void actionPerformed (ActionEvent e)
73     {
74         String cmd = e.getActionCommand();
75         if (cmd.equals("ok")) {
76             System.exit(0);
77         } else {
78             setVisible(false);
79         }
80     }
81
82     /** Used to look up localized messages. */
83     protected String get (String key)
84     {
85         // if this string is tainted, we don't translate it, instead we
86         // simply remove the taint character and return it to the caller
87         if (MessageUtil.isTainted(key)) {
88             return MessageUtil.untaint(key);
89         }
90         try {
91             return _msgs.getString(key);
92         } catch (MissingResourceException mre) {
93             log.warning("Missing translation message '" + key + "'.");
94             return key;
95         }
96     }
97
98     protected Getdown _getdown;
99     protected ResourceBundle _msgs;
100 }