KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > memoire > vainstall > xui > XuiLicenseKeyPanel


1 /**
2  * $RCSfile: XuiLicenseKeyPanel.java,v $
3  * @creation 01/02/00
4  * @modification $Date: 2002/06/05 16:46:19 $
5  */

6
7 package com.memoire.vainstall.xui;
8
9 import java.io.*;
10 import java.awt.*;
11 import java.awt.event.*;
12 import javax.swing.*;
13 import javax.swing.filechooser.*;
14 import javax.swing.border.*;
15 import com.memoire.vainstall.VALicenseKeyStep;
16 import com.memoire.vainstall.VAGlobals;
17 import com.memoire.vainstall.AbstractInstall;
18 import com.memoire.vainstall.LicenseKeySupport;
19 /**
20  * @version $Id: XuiLicenseKeyPanel.java,v 1.1 2002/06/05 16:46:19 deniger Exp $
21  * @author Axel von Arnim
22  */

23
24 public class XuiLicenseKeyPanel
25        extends XuiAbstractPanel
26        implements VALicenseKeyStep
27 {
28   JPanel pnFields;
29   JButton btBrowse_;
30   JLabel lbLabels[] = new JLabel[0];
31   JTextField tfFields[] = new JTextField[0];
32   JTextField tfUri;
33   JPanel pnRegPage;
34   
35   public XuiLicenseKeyPanel()
36   {
37     super();
38     
39     setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
40     
41     
42     JPanel pnMain=new XuiPanel();
43     pnMain.setLayout(new BorderLayout());
44     pnMain.setBorder(new EmptyBorder(5,5,5,5));
45     pnMain.setForeground(new Color(128,255,255));
46
47     JPanel pnHaut=new XuiPanel();
48     pnHaut.setLayout(new BorderLayout(0,0));
49     pnHaut.setBorder(new CompoundBorder
50             (new LineBorder(Color.black,2),
51              new CompoundBorder(new EmptyBorder(5,5,5,5),
52                         new LineBorder(Color.black,2))));
53     
54     /* code below should use VAGlobals.i18n("UI_License")
55      * instead of string */

56     XuiLabel lbTitle=new XuiLabel("Enter License Information");
57     lbTitle.setFont(new Font("SansSerif",Font.PLAIN,16));
58     lbTitle.setOpaque(true);
59     lbTitle.setBorder(new EmptyBorder(new Insets(5, 0, 5, 0)));
60     lbTitle.setBackground(pnMain.getBackground().darker());
61     lbTitle.setForeground(Color.white);
62     pnHaut.add(BorderLayout.NORTH, lbTitle);
63     pnFields = new JPanel();
64     pnFields.setLayout(new GridBagLayout());
65     pnHaut.add(BorderLayout.CENTER, pnFields);
66     
67     pnMain.add(pnHaut);
68   
69     JPanel q=new JPanel();
70     q.setOpaque(false);
71     q.setBorder(null);
72     q.setLayout(new BorderLayout());
73     q.add(lbTitle ,BorderLayout.NORTH);
74     q.add(pnHaut,BorderLayout.CENTER);
75    
76     pnMain.add(q,BorderLayout.NORTH);
77     
78     JPanel pnImage=XuiImagePanel.IMAGE_PANEL;
79     add(pnImage,BorderLayout.WEST);
80     add(pnMain,BorderLayout.CENTER);
81   }
82   
83   public void setLicenseKeySupport(LicenseKeySupport lks)
84   {
85     final LicenseKeySupport.FieldInfo fis[] = lks.getFieldInfo();
86     final String JavaDoc uri = lks.getRegistrationPage();
87     
88     if(uri != null) {
89       // if uri is specified create uri panel at the top of uri window
90
pnRegPage = new JPanel();
91       pnRegPage.setLayout(new GridBagLayout());
92       XuiLabel lbReg = new XuiLabel("Product Registraion Page");
93       pnRegPage.add(lbReg,
94         new GridBagConstraints(0,0,2,1,
95           1.0,0.0,
96           GridBagConstraints.CENTER,
97           GridBagConstraints.HORIZONTAL,
98           new Insets(1,1,1,1),0,0));
99       tfUri = new JTextField();
100       tfUri.setText(uri);
101       tfUri.setEditable(false);
102       pnRegPage.add(tfUri,
103         new GridBagConstraints(0,1,1,1,
104           1.0,0.0,
105           GridBagConstraints.CENTER,
106           GridBagConstraints.HORIZONTAL,
107           new Insets(1,1,1,1),0,0));
108       if(AbstractInstall.IS_WIN){
109         XuiButton bt = new XuiButton("View ...");
110         pnRegPage.add(bt,
111           new GridBagConstraints(1,1,1,1,
112             0.0,0.0,
113             GridBagConstraints.CENTER,
114             GridBagConstraints.NONE,
115             new Insets(1,1,1,1),0,0));
116         bt.addActionListener(new ActionListener(){
117           public void actionPerformed(ActionEvent evt){
118             try {
119               String JavaDoc os = System.getProperty("os.name");
120               if(os.startsWith("Windows 2000") ||
121                  os.startsWith("Windows NT")) {
122                 // not tested on Windows NT 4.0
123
Runtime.getRuntime().exec(new String JavaDoc[]{"cmd.exe", "/C", "\"start "+uri+"\""});
124               } else {
125                 // not tested at all
126
Runtime.getRuntime().exec(new String JavaDoc[]{"command.com", "/C", "\"start "+uri+"\""});
127               }
128             } catch (RuntimeException JavaDoc ex) {
129               throw ex;
130             } catch (Exception JavaDoc ex) {
131               throw new RuntimeException JavaDoc(ex.toString());
132             }
133           }
134         });
135       }
136       pnFields.add(pnRegPage,
137           new GridBagConstraints(0,0,2,1,
138             0.1,0.0,
139             GridBagConstraints.CENTER,
140             GridBagConstraints.HORIZONTAL,
141             new Insets(2,2,2,2),0,0));
142     }
143     tfFields = new JTextField[fis.length];
144     lbLabels = new JLabel[fis.length];
145     for(int i=0; i<fis.length; i++) {
146       lbLabels[i] = new XuiLabel(fis[i].name+":");
147       pnFields.add(lbLabels[i],
148           new GridBagConstraints(0,i+1,1,1,
149             0.0,0.0,
150             GridBagConstraints.WEST,
151             GridBagConstraints.NONE,
152             new Insets(2,2,2,2),0,0));
153       tfFields[i] = new JTextField();
154       tfFields[i].setColumns(fis[i].size);
155       tfFields[i].setText(fis[i].text);
156       pnFields.add(tfFields[i],
157           new GridBagConstraints(1,i+1,1,1,
158             0.0,0.0,
159             GridBagConstraints.WEST,
160             GridBagConstraints.NONE,
161             new Insets(2,2,2,2),0,0));
162     }
163     pnFields.invalidate();
164     validate();
165   }
166   
167   public boolean getGetFields(LicenseKeySupport lks)
168   {
169     String JavaDoc rc[] = new String JavaDoc[tfFields.length];
170     for(int i=0; i<tfFields.length; i++) {
171       rc[i]=tfFields[i].getText().trim();
172     }
173     lks.setFieldValues(rc);
174     if( ! lks.isLicenseKeyValid() ) {
175       /* JOptionPane.showMessageDialog(
176         this,
177         "Invalid License Key", //VAGlobals.i18n("UI_MustChoose")
178         VAGlobals.i18n("UI_Error"),
179         JOptionPane.ERROR_MESSAGE); */

180       return false;
181     }
182     return true;
183   }
184   
185 }
186
Popular Tags