Skip to content

Commit c237ef7

Browse files
committed
Better terms and conditions when the app loads
1 parent 86d4fe0 commit c237ef7

File tree

3 files changed

+177
-15
lines changed

3 files changed

+177
-15
lines changed

conf/termsandconditions.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Please put the terms and conditions here......
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
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+
}

src/java/main/com/topcoder/umltool/deploy/UMLToolDeploy.java

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
import java.io.IOException;
88
import java.lang.Thread.UncaughtExceptionHandler;
99

10+
import javax.swing.JFrame;
1011
import javax.swing.UIDefaults;
1112
import javax.swing.UIManager;
1213
import javax.swing.plaf.FontUIResource;
1314

1415
import com.topcoder.umltool.deploy.actions.ExportAllDiagramsAction;
1516
import com.topcoder.util.log.Log;
1617
import com.topcoder.util.log.LogFactory;
17-
1818
import com.topcoder.macosx.MacOSXAdapter;
1919

2020
/**
@@ -154,25 +154,41 @@ public static void main(final String[] args) {
154154
}
155155
}
156156

157-
// To be replaced with a custom class loader.
158-
final SplashScreen splashScreen = new SplashScreen();
159-
splashScreen.setVisible(true);
157+
showMainFrame(args, new SplashScreen());
158+
}
160159

161-
try {
162-
Thread.sleep(100);
163-
} catch (InterruptedException e) {
164-
DeployHelper.logException(e);
160+
/**
161+
* Shows the main frame. It could be terms and conditions frame of the actual main frame.
162+
* @param args the command line arguments.
163+
* @param splashScreen the splash screen if it needs to be shown first.
164+
*/
165+
public static void showMainFrame(final String[] args, final SplashScreen splashScreen) {
166+
if (splashScreen != null) {
167+
// To be replaced with a custom class loader.
168+
splashScreen.setVisible(true);
169+
170+
try {
171+
Thread.sleep(100);
172+
} catch (InterruptedException e) {
173+
DeployHelper.logException(e);
174+
}
165175
}
166176

167177
javax.swing.SwingUtilities.invokeLater(new Runnable() {
168178
public void run() {
169179
String fileToLoad = null;
170-
MainFrame mainFrame = null;
180+
JFrame mainFrame = null;
181+
boolean tacAccepted = Boolean.parseBoolean(DeployHelper.getProperty("com.topcoder.umltool.deploy",
182+
"TermsAndConditionsAccepted", "false"));
171183
if (args.length > 0) {
172184
fileToLoad = args[0];
173185
}
174186
try {
175-
mainFrame = new MainFrame();
187+
if (tacAccepted) {
188+
mainFrame = new MainFrame();
189+
} else {
190+
mainFrame = new TermsAndConditionsFrame(args);
191+
}
176192
try {
177193
int width =
178194
Integer.parseInt(DeployHelper.getProperty("com.topcoder.umltool.deploy", "Width"));
@@ -182,7 +198,6 @@ public void run() {
182198
} catch (Exception e) {
183199
mainFrame.setSize(mainFrame.getMaximumSize());
184200
}
185-
186201
} catch (DeployConfigException e1) {
187202
DeployHelper.logException(e1);
188203
splashScreen.close();
@@ -205,8 +220,10 @@ public void run() {
205220
(Class[]) null));
206221
// register the file handler for opening files double-clicked in finder or drag and dropped
207222
// onto the application icon
208-
MacOSXAdapter.setFileHandler(mainFrame, mainFrame.getClass().getDeclaredMethod(
209-
"loadProject", new Class[] {String.class}));
223+
if (tacAccepted) {
224+
MacOSXAdapter.setFileHandler(mainFrame, mainFrame.getClass().getDeclaredMethod(
225+
"loadProject", new Class[] {String.class}));
226+
}
210227
} catch (Exception e) {
211228
DeployHelper.logException(new DeployConfigException(
212229
"Error while loading the MacOSXAdapter", e));
@@ -230,11 +247,16 @@ public void run() {
230247
} else if ("xmi".equals(extension)) {
231248
openType = MainFrame.OPEN_PROJECT_XMI_TC;
232249
}
233-
mainFrame.loadProject(file, openType);
250+
if (tacAccepted) {
251+
((MainFrame) mainFrame).loadProject(file, openType);
252+
}
234253
}
235254

236255
mainFrame.setVisible(true);
237-
splashScreen.close();
256+
257+
if (splashScreen != null) {
258+
splashScreen.close();
259+
}
238260
}
239261
});
240262
}

0 commit comments

Comments
 (0)