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