| 1 6 7 package com.memoire.vainstall.gui; 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 23 24 public class VALicenseKeyPanel 25 extends VAPanel 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 VALicenseKeyPanel() 36 { 37 super(); 38 39 setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); 40 41 JPanel pnMain=new JPanel(); 42 pnMain.setBorder(new CompoundBorder(new EtchedBorder(), 43 new EmptyBorder(new Insets(5, 5, 5, 5)))); 44 pnMain.setLayout(new BoxLayout(pnMain, BoxLayout.Y_AXIS)); 45 46 JPanel pnHaut=new JPanel(); 47 pnHaut.setLayout(new BorderLayout()); 48 50 JLabel lbTitle=new JLabel("Enter License Information"); 51 lbTitle.setFont(lbTitle.getFont().deriveFont(Font.BOLD, 20)); 52 lbTitle.setOpaque(true); 53 lbTitle.setBorder(new EmptyBorder(new Insets(5, 0, 5, 0))); 54 lbTitle.setBackground(pnMain.getBackground().darker()); 55 lbTitle.setForeground(Color.white); 56 pnHaut.add(BorderLayout.NORTH, lbTitle); 57 pnFields = new JPanel(); 58 pnFields.setLayout(new GridBagLayout()); 59 pnHaut.add(BorderLayout.CENTER, pnFields); 60 61 pnMain.add(pnHaut); 62 63 64 JComponent pnImage=VAImagePanel.IMAGE_PANEL; 65 add(pnImage); 66 add(pnMain); 67 } 68 69 public void setLicenseKeySupport(LicenseKeySupport lks) 70 { 71 final LicenseKeySupport.FieldInfo fis[] = lks.getFieldInfo(); 72 final String uri = lks.getRegistrationPage(); 73 74 if(uri != null) { 75 pnRegPage = new JPanel(); 77 pnRegPage.setLayout(new GridBagLayout()); 78 JLabel lbReg = new JLabel("Product Registraion Page"); 79 pnRegPage.add(lbReg, 80 new GridBagConstraints(0,0,2,1, 81 1.0,0.0, 82 GridBagConstraints.CENTER, 83 GridBagConstraints.HORIZONTAL, 84 new Insets(1,1,1,1),0,0)); 85 tfUri = new JTextField(); 86 tfUri.setText(uri); 87 tfUri.setEditable(false); 88 pnRegPage.add(tfUri, 89 new GridBagConstraints(0,1,1,1, 90 1.0,0.0, 91 GridBagConstraints.CENTER, 92 GridBagConstraints.HORIZONTAL, 93 new Insets(1,1,1,1),0,0)); 94 if(AbstractInstall.IS_WIN){ 95 JButton bt = new JButton("View ..."); 96 pnRegPage.add(bt, 97 new GridBagConstraints(1,1,1,1, 98 0.0,0.0, 99 GridBagConstraints.CENTER, 100 GridBagConstraints.NONE, 101 new Insets(1,1,1,1),0,0)); 102 bt.addActionListener(new ActionListener(){ 103 public void actionPerformed(ActionEvent evt){ 104 try { 105 String os = System.getProperty("os.name"); 106 if(os.startsWith("Windows 2000") || 107 os.startsWith("Windows NT")) { 108 Runtime.getRuntime().exec(new String []{"cmd.exe", "/C", "\"start "+uri+"\""}); 110 } else { 111 Runtime.getRuntime().exec(new String []{"command.com", "/C", "\"start "+uri+"\""}); 113 } 114 } catch (RuntimeException ex) { 115 throw ex; 116 } catch (Exception ex) { 117 throw new RuntimeException (ex.toString()); 118 } 119 } 120 }); 121 } 122 pnFields.add(pnRegPage, 123 new GridBagConstraints(0,0,2,1, 124 0.1,0.0, 125 GridBagConstraints.CENTER, 126 GridBagConstraints.HORIZONTAL, 127 new Insets(2,2,2,2),0,0)); 128 } 129 tfFields = new JTextField[fis.length]; 130 lbLabels = new JLabel[fis.length]; 131 for(int i=0; i<fis.length; i++) { 132 lbLabels[i] = new JLabel(fis[i].name+":"); 133 pnFields.add(lbLabels[i], 134 new GridBagConstraints(0,i+1,1,1, 135 0.0,0.0, 136 GridBagConstraints.WEST, 137 GridBagConstraints.NONE, 138 new Insets(2,2,2,2),0,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], 143 new GridBagConstraints(1,i+1,1,1, 144 0.0,0.0, 145 GridBagConstraints.WEST, 146 GridBagConstraints.NONE, 147 new Insets(2,2,2,2),0,0)); 148 } 149 pnFields.invalidate(); 150 validate(); 151 } 152 153 public boolean getGetFields(LicenseKeySupport lks) 154 { 155 String rc[] = new String [tfFields.length]; 156 for(int i=0; i<tfFields.length; i++) { 157 rc[i]=tfFields[i].getText().trim(); 158 } 159 lks.setFieldValues(rc); 160 if( ! lks.isLicenseKeyValid() ) { 161 166 return false; 167 } 168 return true; 169 } 170 171 } 172 | Popular Tags |