001: package com.xoetrope.editor.lm;
002:
003: import com.xoetrope.carousel.install.XuiProProjectCheck;
004: import java.awt.BorderLayout;
005: import java.awt.Dimension;
006: import java.awt.event.ActionEvent;
007: import java.io.BufferedReader;
008: import java.io.File;
009: import java.io.FileInputStream;
010: import java.io.IOException;
011: import java.io.InputStreamReader;
012: import java.net.URL;
013: import java.text.SimpleDateFormat;
014: import java.util.Date;
015: import javax.swing.JButton;
016: import javax.swing.JDialog;
017: import javax.swing.JFileChooser;
018: import javax.swing.JLabel;
019: import javax.swing.JPanel;
020: import javax.swing.JScrollPane;
021: import javax.swing.JTabbedPane;
022: import javax.swing.JTable;
023: import javax.swing.JTextArea;
024: import javax.swing.JTextField;
025: import javax.swing.SwingConstants;
026: import javax.swing.WindowConstants;
027: import javax.swing.border.EmptyBorder;
028: import javax.swing.table.DefaultTableModel;
029: import net.xoetrope.editor.lm.LicenseManager;
030: import net.xoetrope.editor.project.XEditorProject;
031: import net.xoetrope.editor.project.XEditorProjectManager;
032: import net.xoetrope.editor.project.helper.AFileFilter;
033:
034: /**
035: * A License Manager dialog
036: * @since 3.2
037: * <p> Copyright (c) Xoetrope Ltd., 2002-2008</p>
038: * <p> License: see License.txt</p>
039: */
040: public class XModuleRegistrationDialog extends JDialog {
041: private JButton jButton1;
042: private JButton jButton2;
043: private JButton jButton3, regButton;
044: private JLabel jLabel1;
045: private JLabel jLabel2;
046: private JLabel instructions;
047: private JPanel modulesPanel;
048: private JPanel registrationPanel;
049: private JPanel jPanel3;
050: private JPanel ossPanel;
051: private JPanel instructionPanel, commercialPanel;
052: private JScrollPane jScrollPane1;
053: private JScrollPane jScrollPane2;
054: private JScrollPane jScrollPane3;
055: private JScrollPane jScrollPane4, commScrollPane;
056: private JTabbedPane tabPanel;
057: private JTable jTable1;
058: private JTextArea jTextArea1;
059: private JTextArea registrationTextArea;
060: private JTextArea ossTextArea, commTextArea;
061: private JTextField registrationFileTextArea, commTextField;
062:
063: private String regText = "";
064: private DefaultTableModel tableModel;
065:
066: private LicenseManager lm;
067:
068: /** Creates new form XModuleRegistrationDialog */
069: public XModuleRegistrationDialog(LicenseManager xplm) {
070: super ();
071: setModal(true);
072:
073: lm = xplm;
074:
075: initComponents();
076: }
077:
078: public void setInfo(String info) {
079: regText = info;
080: registrationTextArea.setText(regText);
081: }
082:
083: private void initComponents() {
084: setTitle("XUI Module Registration");
085:
086: jScrollPane3 = new JScrollPane();
087: jTextArea1 = new JTextArea();
088: tabPanel = new JTabbedPane();
089: modulesPanel = new JPanel();
090: jLabel1 = new JLabel();
091: jScrollPane2 = new JScrollPane();
092: jTable1 = new JTable();
093: registrationPanel = new JPanel();
094: jLabel2 = new JLabel();
095: registrationFileTextArea = new JTextField();
096: jButton1 = new JButton();
097: jScrollPane1 = new JScrollPane();
098: registrationTextArea = new JTextArea();
099: ossPanel = new JPanel();
100: commercialPanel = new JPanel();
101:
102: jScrollPane4 = new JScrollPane();
103: ossTextArea = new JTextArea();
104: instructionPanel = new JPanel();
105: instructions = new JLabel();
106: jPanel3 = new JPanel();
107: jButton2 = new JButton();
108: jButton3 = new JButton();
109:
110: jTextArea1.setColumns(20);
111: jTextArea1.setRows(5);
112: jScrollPane3.setViewportView(jTextArea1);
113:
114: setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
115: modulesPanel.setLayout(null);
116:
117: jLabel1.setText("Modules: ");
118: modulesPanel.add(jLabel1);
119: jLabel1.setBounds(10, 10, 50, 14);
120:
121: String userName = System.getProperty("user.name");
122: jTable1
123: .setModel(tableModel = new DefaultTableModel(
124: new Object[][] {
125: { "XUI Pro", userName, "n/a", "n/a",
126: "1" },
127: { "XUI Pro Widgets", userName, "n/a",
128: "n/a", "0" },
129: { "XUI Pro SVG Widgets", userName,
130: "n/a", "n/a", "0" },
131: { "XUI Pro Hibernate", userName, "n/a",
132: "n/a", "0" },
133: { "XUI Pro Comms", userName, "n/a",
134: "n/a", "0" },
135: { "XUI Pro Form Builder", userName,
136: "n/a", "n/a", "0" },
137: { "XUI Pro Surveys", userName, "n/a",
138: "n/a", "0" },
139: { "XUI Pro Catalogs", userName, "n/a",
140: "n/a", "0" },
141: { "XUI Pro Localization", userName,
142: "n/a", "n/a", "0" } },
143: new String[] { "Module", "Registered To",
144: "Mode", "Expires", "Seats" }));
145: jScrollPane2.setViewportView(jTable1);
146:
147: modulesPanel.add(jScrollPane2);
148: jScrollPane2.setBounds(70, 10, 620, 300);
149:
150: registrationPanel.setLayout(null);
151:
152: jLabel2.setHorizontalAlignment(SwingConstants.RIGHT);
153: jLabel2.setText("Registration File:");
154: registrationPanel.add(jLabel2);
155: jLabel2.setBounds(10, 12, 100, 14);
156:
157: registrationFileTextArea.setText("C:\\???\\"
158: + System.getProperty("user.name") + ".reg");
159: registrationPanel.add(registrationFileTextArea);
160: registrationFileTextArea.setBounds(120, 10, 490, 20);
161:
162: jButton1.setText("...");
163: jButton1.addActionListener(new java.awt.event.ActionListener() {
164: public void actionPerformed(ActionEvent evt) {
165: browse(evt);
166: }
167: });
168: registrationPanel.add(jButton1);
169: jButton1.setBounds(615, 10, 40, 20);
170:
171: regButton = new JButton("Register");
172: registrationPanel.add(regButton);
173: regButton.setBounds(615, 290, 80, 20);
174: regButton
175: .addActionListener(new java.awt.event.ActionListener() {
176: public void actionPerformed(ActionEvent evt) {
177: register(evt);
178: }
179: });
180:
181: registrationTextArea.setColumns(80);
182: registrationTextArea.setRows(5);
183: registrationTextArea.setText(regText);
184: jScrollPane1.setViewportView(registrationTextArea);
185:
186: registrationPanel.add(jScrollPane1);
187: jScrollPane1.setBounds(120, 40, 490, 270);
188:
189: ossTextArea.setColumns(80);
190: ossTextArea.setRows(5);
191: jScrollPane4.setViewportView(ossTextArea);
192: jScrollPane4.setBounds(10, 10, 680, 300);
193: ossPanel.setLayout(null);
194: ossPanel.add(jScrollPane4);
195: try {
196: URL licenseURL = getClass().getClassLoader().getResource(
197: "license.txt");
198: BufferedReader br = new BufferedReader(
199: new InputStreamReader(licenseURL.openStream()));
200: String s = "";
201: String text = "";
202: do {
203: text += s + "\r\n";
204: s = br.readLine();
205: } while (s != null);
206:
207: ossTextArea.setText(text);
208: } catch (IOException ex) {
209: ex.printStackTrace();
210: }
211:
212: commTextArea = new JTextArea("comm license");
213: commTextArea.setColumns(80);
214: commTextArea.setRows(5);
215: try {
216: URL licenseURL = getClass().getClassLoader().getResource(
217: "commercial_license.txt");
218: BufferedReader br = new BufferedReader(
219: new InputStreamReader(licenseURL.openStream()));
220: String s = "";
221: String text = "";
222: do {
223: text += s + "\r\n";
224: s = br.readLine();
225: } while (s != null);
226:
227: commTextArea.setText(text);
228: } catch (IOException ex) {
229: ex.printStackTrace();
230: }
231:
232: commScrollPane = new JScrollPane();
233: commScrollPane.setViewportView(commTextArea);
234: commScrollPane.setBounds(10, 10, 680, 300);
235: commercialPanel.setLayout(null);
236: commercialPanel.add(commScrollPane);
237:
238: instructions.setHorizontalAlignment(SwingConstants.LEFT);
239: String instructionText = "<html><p><b>Thank you for using XUI Pro.</b></p><br/>"
240: + "<p><i>Please follow the instructions below to register your use of this software.</i></p><br/>"
241: + "<p>The software included in XUI Pro is commercial software licensed under both a GPL Open Source License and a Commercial License. If you use the software for business purposes, regadless of whether or not you redistribute the software you must purchase a full commercial license from Xoetrope.</p><br/>"
242: + "<p>This dialog provides information about the available components and the license registrations.</p>"
243: + "<p><ol><li>Review the modules available and compare this to your usage of XUI Pro</li><li>Check the licenses you have registered</li><li>Visit <b>http://www.xoetrope.com/xui/register</b> to review and purchase additional licenses where required</li><li>Download and load the registration information or file</li><li>Check that the modules you require are now licensed</li></ol></p>"
244: + "<p>Both the open source and commercial licenses are available for your review.</p>"
245: + "</html>";
246: instructions.setText(instructionText);
247: instructions.setBorder(new EmptyBorder(10, 10, 10, 10));
248: instructions.setVerticalAlignment(SwingConstants.TOP);
249: instructions.setMaximumSize(new Dimension(700, 320));
250: instructions.setPreferredSize(new Dimension(700, 320));
251:
252: instructionPanel.setLayout(new BorderLayout());
253: instructionPanel.add(instructions, BorderLayout.CENTER);
254:
255: tabPanel.addTab("Instructions", instructionPanel);
256: tabPanel.addTab("Modules", modulesPanel); // NOI18N
257: tabPanel.addTab("Registration", registrationPanel); // NOI18N
258: tabPanel.addTab("Open Source Use", ossPanel); // NOI18N
259: tabPanel.addTab("Commercial Use", commercialPanel); // NOI18N
260:
261: getContentPane()
262: .add(tabPanel, java.awt.BorderLayout.PAGE_START);
263:
264: jPanel3.setLayout(new java.awt.FlowLayout(
265: java.awt.FlowLayout.RIGHT));
266:
267: jButton2.setText("OK");
268: jButton2.addActionListener(new java.awt.event.ActionListener() {
269: public void actionPerformed(ActionEvent evt) {
270: okClicked(evt);
271: }
272: });
273:
274: jPanel3.add(jButton2);
275:
276: jButton3.setText("Cancel");
277: jButton3.addActionListener(new java.awt.event.ActionListener() {
278: public void actionPerformed(ActionEvent evt) {
279: cancelDialog(evt);
280: }
281: });
282:
283: jPanel3.add(jButton3);
284:
285: getContentPane().add(jPanel3, java.awt.BorderLayout.SOUTH);
286:
287: updateLicenseInfo();
288: pack();
289: }
290:
291: private void cancelDialog(ActionEvent evt) {
292: setVisible(false);
293: }
294:
295: private void okClicked(ActionEvent evt) {
296: setVisible(false);
297: }
298:
299: private void register(ActionEvent evt) {
300: regText = registrationTextArea.getText();
301: lm.processRegistration(regText);
302: updateLicenseInfo();
303:
304: XuiProProjectCheck.initializeModules(getClass()
305: .getClassLoader());
306: XEditorProject project = (XEditorProject) XEditorProjectManager
307: .getCurrentProject();
308: XEditorProjectManager.projectInitialized(project);
309: }
310:
311: private void updateLicenseInfo() {
312: SimpleDateFormat df = new SimpleDateFormat("MMM dd yyyy");
313:
314: String userName = System.getProperty("user.name");
315: if (lm.isUserRegistered("XUI Pro")) {
316: int rows = tableModel.getRowCount();
317: for (int i = 0; i < rows; i++) {
318: // "Module", "Registered To", "Mode", "Expires", "Seats"
319: String module = (String) tableModel.getValueAt(i, 0);
320: LicenseEntry le = ((XuiProLicenseManager) lm)
321: .getLicenseDetails(module);
322: if (le != null) {
323: tableModel.setValueAt(userName, i, 1);
324: tableModel.setValueAt(le.mode, i, 2);
325:
326: Date date = new Date(le.expiry);
327: tableModel.setValueAt(df.format(date), i, 3);
328:
329: tableModel.setValueAt(le.seats, i, 4);
330: } else {
331: tableModel.setValueAt("n/a", i, 1);
332: tableModel.setValueAt("n/a", i, 2);
333: tableModel.setValueAt("n/a", i, 3);
334: tableModel.setValueAt("0", i, 4);
335: }
336: }
337: }
338: }
339:
340: private void browse(ActionEvent evt) {
341: try {
342: // Ask the user to locate the file
343: JFileChooser chooser = new JFileChooser();
344: AFileFilter myFilter = new AFileFilter("reg", "REG files");
345: myFilter.setDirMustExist(true);
346: myFilter.setFileMustExist(true);
347: chooser
348: .setDialogTitle("Please select the location of the registration file.");
349: chooser.setFileFilter(myFilter);
350: chooser.setFileSelectionMode(chooser.FILES_ONLY);
351: if (chooser.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
352: String fileName = chooser.getSelectedFile().toString();
353: registrationFileTextArea.setText(fileName);
354:
355: FileInputStream fis = new FileInputStream(new File(
356: fileName));
357: String text = "";
358: int len;
359: byte[] buf = new byte[4096];
360: try {
361: while ((len = fis.read(buf, 0, 4096)) >= 0) {
362: text += new String(buf, 0, len);
363: }
364:
365: registrationTextArea.setText(text);
366: register(null);
367:
368: fis.close();
369: } catch (IOException ex) {
370: ex.printStackTrace();
371: }
372: }
373: } catch (Exception ex1) {
374: }
375: }
376:
377: public String getInfo() {
378: return regText;
379: }
380: }
|