001: /**
002: * $RCSfile: XuiLicenseKeyPanel.java,v $
003: * @creation 01/02/00
004: * @modification $Date: 2002/06/05 16:46:19 $
005: */package com.memoire.vainstall.xui;
006:
007: import java.io.*;
008: import java.awt.*;
009: import java.awt.event.*;
010: import javax.swing.*;
011: import javax.swing.filechooser.*;
012: import javax.swing.border.*;
013: import com.memoire.vainstall.VALicenseKeyStep;
014: import com.memoire.vainstall.VAGlobals;
015: import com.memoire.vainstall.AbstractInstall;
016: import com.memoire.vainstall.LicenseKeySupport;
017:
018: /**
019: * @version $Id: XuiLicenseKeyPanel.java,v 1.1 2002/06/05 16:46:19 deniger Exp $
020: * @author Axel von Arnim
021: */
022:
023: public class XuiLicenseKeyPanel extends XuiAbstractPanel implements
024: VALicenseKeyStep {
025: JPanel pnFields;
026: JButton btBrowse_;
027: JLabel lbLabels[] = new JLabel[0];
028: JTextField tfFields[] = new JTextField[0];
029: JTextField tfUri;
030: JPanel pnRegPage;
031:
032: public XuiLicenseKeyPanel() {
033: super ();
034:
035: setLayout(new BoxLayout(this , BoxLayout.X_AXIS));
036:
037: JPanel pnMain = new XuiPanel();
038: pnMain.setLayout(new BorderLayout());
039: pnMain.setBorder(new EmptyBorder(5, 5, 5, 5));
040: pnMain.setForeground(new Color(128, 255, 255));
041:
042: JPanel pnHaut = new XuiPanel();
043: pnHaut.setLayout(new BorderLayout(0, 0));
044: pnHaut.setBorder(new CompoundBorder(new LineBorder(Color.black,
045: 2), new CompoundBorder(new EmptyBorder(5, 5, 5, 5),
046: new LineBorder(Color.black, 2))));
047:
048: /* code below should use VAGlobals.i18n("UI_License")
049: * instead of string */
050: XuiLabel lbTitle = new XuiLabel("Enter License Information");
051: lbTitle.setFont(new Font("SansSerif", Font.PLAIN, 16));
052: lbTitle.setOpaque(true);
053: lbTitle.setBorder(new EmptyBorder(new Insets(5, 0, 5, 0)));
054: lbTitle.setBackground(pnMain.getBackground().darker());
055: lbTitle.setForeground(Color.white);
056: pnHaut.add(BorderLayout.NORTH, lbTitle);
057: pnFields = new JPanel();
058: pnFields.setLayout(new GridBagLayout());
059: pnHaut.add(BorderLayout.CENTER, pnFields);
060:
061: pnMain.add(pnHaut);
062:
063: JPanel q = new JPanel();
064: q.setOpaque(false);
065: q.setBorder(null);
066: q.setLayout(new BorderLayout());
067: q.add(lbTitle, BorderLayout.NORTH);
068: q.add(pnHaut, BorderLayout.CENTER);
069:
070: pnMain.add(q, BorderLayout.NORTH);
071:
072: JPanel pnImage = XuiImagePanel.IMAGE_PANEL;
073: add(pnImage, BorderLayout.WEST);
074: add(pnMain, BorderLayout.CENTER);
075: }
076:
077: public void setLicenseKeySupport(LicenseKeySupport lks) {
078: final LicenseKeySupport.FieldInfo fis[] = lks.getFieldInfo();
079: final String uri = lks.getRegistrationPage();
080:
081: if (uri != null) {
082: // if uri is specified create uri panel at the top of uri window
083: pnRegPage = new JPanel();
084: pnRegPage.setLayout(new GridBagLayout());
085: XuiLabel lbReg = new XuiLabel("Product Registraion Page");
086: pnRegPage.add(lbReg, new GridBagConstraints(0, 0, 2, 1,
087: 1.0, 0.0, GridBagConstraints.CENTER,
088: GridBagConstraints.HORIZONTAL, new Insets(1, 1, 1,
089: 1), 0, 0));
090: tfUri = new JTextField();
091: tfUri.setText(uri);
092: tfUri.setEditable(false);
093: pnRegPage.add(tfUri, new GridBagConstraints(0, 1, 1, 1,
094: 1.0, 0.0, GridBagConstraints.CENTER,
095: GridBagConstraints.HORIZONTAL, new Insets(1, 1, 1,
096: 1), 0, 0));
097: if (AbstractInstall.IS_WIN) {
098: XuiButton bt = new XuiButton("View ...");
099: pnRegPage.add(bt, new GridBagConstraints(1, 1, 1, 1,
100: 0.0, 0.0, GridBagConstraints.CENTER,
101: GridBagConstraints.NONE,
102: new Insets(1, 1, 1, 1), 0, 0));
103: bt.addActionListener(new ActionListener() {
104: public void actionPerformed(ActionEvent evt) {
105: try {
106: String os = System.getProperty("os.name");
107: if (os.startsWith("Windows 2000")
108: || os.startsWith("Windows NT")) {
109: // not tested on Windows NT 4.0
110: Runtime
111: .getRuntime()
112: .exec(
113: new String[] {
114: "cmd.exe",
115: "/C",
116: "\"start "
117: + uri
118: + "\"" });
119: } else {
120: // not tested at all
121: Runtime
122: .getRuntime()
123: .exec(
124: new String[] {
125: "command.com",
126: "/C",
127: "\"start "
128: + uri
129: + "\"" });
130: }
131: } catch (RuntimeException ex) {
132: throw ex;
133: } catch (Exception ex) {
134: throw new RuntimeException(ex.toString());
135: }
136: }
137: });
138: }
139: pnFields.add(pnRegPage, new GridBagConstraints(0, 0, 2, 1,
140: 0.1, 0.0, GridBagConstraints.CENTER,
141: GridBagConstraints.HORIZONTAL, new Insets(2, 2, 2,
142: 2), 0, 0));
143: }
144: tfFields = new JTextField[fis.length];
145: lbLabels = new JLabel[fis.length];
146: for (int i = 0; i < fis.length; i++) {
147: lbLabels[i] = new XuiLabel(fis[i].name + ":");
148: pnFields.add(lbLabels[i], new GridBagConstraints(0, i + 1,
149: 1, 1, 0.0, 0.0, GridBagConstraints.WEST,
150: GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0,
151: 0));
152: tfFields[i] = new JTextField();
153: tfFields[i].setColumns(fis[i].size);
154: tfFields[i].setText(fis[i].text);
155: pnFields.add(tfFields[i], new GridBagConstraints(1, i + 1,
156: 1, 1, 0.0, 0.0, GridBagConstraints.WEST,
157: GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0,
158: 0));
159: }
160: pnFields.invalidate();
161: validate();
162: }
163:
164: public boolean getGetFields(LicenseKeySupport lks) {
165: String rc[] = new String[tfFields.length];
166: for (int i = 0; i < tfFields.length; i++) {
167: rc[i] = tfFields[i].getText().trim();
168: }
169: lks.setFieldValues(rc);
170: if (!lks.isLicenseKeyValid()) {
171: /* JOptionPane.showMessageDialog(
172: this,
173: "Invalid License Key", //VAGlobals.i18n("UI_MustChoose")
174: VAGlobals.i18n("UI_Error"),
175: JOptionPane.ERROR_MESSAGE); */
176: return false;
177: }
178: return true;
179: }
180:
181: }
|