22
33import static fi .helsinki .cs .tmc .ui .Boxer .hbox ;
44import static fi .helsinki .cs .tmc .ui .Boxer .hglue ;
5+
6+ import fi .helsinki .cs .tmc .utilities .BrowserOpener ;
7+
58import java .awt .Component ;
69import java .awt .Dimension ;
710import java .awt .Toolkit ;
811import java .awt .datatransfer .Clipboard ;
912import java .awt .datatransfer .StringSelection ;
1013import java .awt .event .ActionEvent ;
1114import java .awt .event .ActionListener ;
12- import java .net .URL ;
15+ import java .io .IOException ;
16+ import java .net .URI ;
17+ import java .net .URISyntaxException ;
1318import java .util .logging .Logger ;
1419import javax .swing .AbstractAction ;
1520import javax .swing .BorderFactory ;
2025import javax .swing .JLabel ;
2126import javax .swing .JPanel ;
2227import javax .swing .JTextField ;
23- import org .openide .awt .HtmlBrowser ;
2428
2529public class PastebinResponseDialog extends JDialog {
2630
2731 private static final Logger log = Logger .getLogger (PastebinResponseDialog .class .getName ());
2832
2933 public PastebinResponseDialog (final String pasteUrl ) {
3034 setTitle ("Pastebin notification" );
31-
35+
3236 // Set location according to screen dimensions
3337 Dimension screenSize = Toolkit .getDefaultToolkit ().getScreenSize ();
3438 this .setLocation (screenSize .width / 2 - (this .getWidth () / 2 ), screenSize .height / 2 - (this .getHeight () / 2 ));
35-
39+
3640 JPanel contentPane = new JPanel ();
3741 contentPane .setBorder (BorderFactory .createEmptyBorder (8 , 8 , 8 , 8 ));
3842 contentPane .setLayout (new BoxLayout (contentPane , BoxLayout .Y_AXIS ));
3943 setContentPane (contentPane );
40-
44+
4145 getContentPane ().add (leftAligned (new JLabel ("Code submitted to TMC pastebin." )));
4246 addVSpace (8 );
4347 JButton viewPasteButton = new JButton (new AbstractAction ("View paste" ) {
4448 @ Override
45- public void actionPerformed (ActionEvent ev ) {
46- try {
47- HtmlBrowser .URLDisplayer .getDefault ().showURLExternal (new URL (pasteUrl ));
48- } catch (Exception ex ) {
49- ConvenientDialogDisplayer .getDefault ().displayError ("Failed to open browser.\n " + ex .getMessage ());
50- }
49+ public void actionPerformed (ActionEvent ev ) {
50+ try {
51+ BrowserOpener .openUrl (URI .create (pasteUrl ));
52+ } catch (URISyntaxException | IOException ex ) {
53+ ConvenientDialogDisplayer .getDefault ().displayError ("Failed to open browser.\n " + ex .getMessage ());
5154 }
55+ }
5256 });
53-
57+
5458 getContentPane ().add (leftAligned (viewPasteButton ));
5559 addVSpace (8 );
56-
60+
5761 final JTextField pasteUrlField = new JTextField (pasteUrl );
5862 pasteUrlField .setEditable (false );
5963 getContentPane ().add (leftAligned (pasteUrlField ));
60-
64+
6165 addVSpace (8 );
62-
66+
6367 JButton okButton = new JButton ("OK" );
6468 okButton .addActionListener (new ActionListener () {
6569 @ Override
@@ -69,28 +73,27 @@ public void actionPerformed(ActionEvent e) {
6973 }
7074 });
7175 getContentPane ().add (hbox (hglue (), okButton ));
72-
76+
7377 JButton copyToClipboardButton = new JButton ("Copy to clipboard" );
7478 copyToClipboardButton .addActionListener (new ActionListener () {
7579 @ Override
7680 public void actionPerformed (ActionEvent e ) {
77- StringSelection stringSelection = new StringSelection (pasteUrl );
81+ StringSelection stringSelection = new StringSelection (pasteUrl );
7882 Clipboard clipboard = Toolkit .getDefaultToolkit ().getSystemClipboard ();
7983 clipboard .setContents (stringSelection , stringSelection );
8084 }
8185 });
8286 getContentPane ().add (hbox (hglue (), copyToClipboardButton ));
83-
87+
8488 pack ();
85-
86-
8789
8890 }
91+
8992 //brutishly borrowed from SuccessfulSubmissionDialog
9093 private void addVSpace (int height ) {
9194 add (Box .createVerticalStrut (height ));
9295 }
93-
96+
9497 private Box leftAligned (Component component ) {
9598 return hbox (component , hglue ());
9699 }
0 commit comments