1
+ /*
2
+ * Copyright (C) 2014 TopCoder Inc., All Rights Reserved.
3
+ */
4
+ package com .topcoder .umltool .deploy ;
5
+
6
+ import java .awt .BorderLayout ;
7
+ import java .awt .Image ;
8
+ import java .awt .event .ActionEvent ;
9
+ import java .awt .event .ActionListener ;
10
+ import java .io .BufferedReader ;
11
+ import java .io .File ;
12
+ import java .io .IOException ;
13
+ import java .io .InputStream ;
14
+ import java .io .InputStreamReader ;
15
+
16
+ import javax .swing .ImageIcon ;
17
+ import javax .swing .JButton ;
18
+ import javax .swing .JFrame ;
19
+ import javax .swing .JPanel ;
20
+ import javax .swing .JTextArea ;
21
+ import javax .swing .SwingUtilities ;
22
+
23
+ import com .topcoder .macosx .MacOSXAdapter ;
24
+ import com .topcoder .util .config .ConfigManager ;
25
+
26
+ /**
27
+ * <p>
28
+ * Terms and Conditions frame of the uml tool.
29
+ * </p>
30
+ *
31
+ * @author duxiaoyang
32
+ * @version 1.0
33
+ */
34
+ public class TermsAndConditionsFrame extends JFrame {
35
+
36
+ /**
37
+ * The serial version uid of this class.
38
+ */
39
+ private static final long serialVersionUID = -6528904504695692820L ;
40
+
41
+ /**
42
+ * <p>
43
+ * Represents the title of the frame.
44
+ * </p>
45
+ */
46
+ private static final String FRAME_TITLE = "TopCoder UML Tool" ;
47
+
48
+ /**
49
+ * <p>
50
+ * Icon file name for frame.
51
+ * <p>
52
+ */
53
+ private static final String ICON_FILE_NAME = "/images/UmlTool_16.png" ;
54
+
55
+ /**
56
+ * <p>
57
+ * Represents the command line arguments.
58
+ * </p>
59
+ */
60
+ private String [] args ;
61
+
62
+ /**
63
+ * Creates an instance of this frame.
64
+ */
65
+ public TermsAndConditionsFrame (String [] args ) throws DeployConfigException {
66
+ super ();
67
+ this .args = args ;
68
+ setTitle (FRAME_TITLE );
69
+ Image image = new ImageIcon (getClass ().getResource (ICON_FILE_NAME )).getImage ();
70
+ this .setIconImage (image );
71
+ init ();
72
+ }
73
+
74
+ /**
75
+ * Initializes the frame.
76
+ * @throws DeployConfigException if any required configuration is missing.
77
+ */
78
+ private void init () throws DeployConfigException {
79
+ this .setDefaultCloseOperation (JFrame .EXIT_ON_CLOSE );
80
+ this .getContentPane ().setLayout (new BorderLayout ());
81
+
82
+ JTextArea textArea = new JTextArea ();
83
+ String tacFile = DeployHelper .getProperty ("com.topcoder.umltool.deploy" , "TermsAndConditionsFileLocation" );
84
+ InputStream stream = getClass ().getClassLoader ().getResourceAsStream (tacFile );
85
+ if (stream == null ) {
86
+ throw new DeployConfigException ("Terms and Conditions config error." );
87
+ }
88
+ BufferedReader reader = new BufferedReader (new InputStreamReader (stream ));
89
+ StringBuilder sb = new StringBuilder ();
90
+ try {
91
+ String line = reader .readLine ();
92
+ while (line != null ) {
93
+ sb .append (line ).append ("\n " );
94
+ line = reader .readLine ();
95
+ }
96
+ } catch (IOException e ) {
97
+ throw new DeployConfigException ("Terms and Conditions config error." , e );
98
+ }
99
+ textArea .setText (sb .toString ());
100
+ textArea .setEditable (false );
101
+ this .add (textArea , BorderLayout .CENTER );
102
+
103
+ JPanel buttonPanel = new JPanel ();
104
+ JButton acceptButton = new JButton ("Accept" );
105
+ acceptButton .addActionListener (new ActionListener () {
106
+ public void actionPerformed (ActionEvent event ) {
107
+ accept ();
108
+ }});
109
+ JButton declineButton = new JButton ("Decline" );
110
+ declineButton .addActionListener (new ActionListener () {
111
+ public void actionPerformed (ActionEvent event ) {
112
+ setVisible (false );
113
+ SwingUtilities .invokeLater (new Runnable () {
114
+ public void run () {
115
+ System .exit (0 );
116
+ }});
117
+ }});
118
+ buttonPanel .add (acceptButton );
119
+ buttonPanel .add (declineButton );
120
+ this .add (buttonPanel , BorderLayout .SOUTH );
121
+ }
122
+
123
+ /**
124
+ * Handles the event when terms and conditions are accepted.
125
+ */
126
+ private void accept () {
127
+ try {
128
+ ConfigManager .getInstance ().createTemporaryProperties ("com.topcoder.umltool.deploy" );
129
+ ConfigManager .getInstance ().setProperty ("com.topcoder.umltool.deploy" , "TermsAndConditionsAccepted" ,
130
+ "true" );
131
+ ConfigManager .getInstance ().commit ("com.topcoder.umltool.deploy" , "" );
132
+
133
+ setVisible (false );
134
+ UMLToolDeploy .showMainFrame (args , null );
135
+ } catch (Exception e ) {
136
+ DeployHelper .logException (e );
137
+ }
138
+ }
139
+ }
0 commit comments