1 7 8 package com.memoire.vainstall.builder.gui; 9 10 import com.memoire.vainstall.VAGlobals; 11 import com.memoire.vainstall.builder.*; 12 13 import java.awt.*; 14 import java.awt.event.*; 15 16 import java.io.File ; 17 18 import javax.swing.*; 19 import javax.swing.border.*; 20 21 38 public class ProductStepLicensePanel extends JPanel implements FocusListener, ActionListener { 39 40 private VAIProductModel model; 41 42 private final static Border loweredBorder = new SoftBevelBorder(BevelBorder.LOWERED); 43 44 RequiredTextField licenseFileNameField; 45 46 JButton licenseFileNameButton; 47 48 JTextField encodingField; 49 50 public ProductStepLicensePanel() { 51 52 setBorder(loweredBorder); 53 54 GridBagLayout layout = new GridBagLayout(); 55 setLayout(layout); 56 57 GridBagConstraints contraint=new GridBagConstraints(); 58 59 JLabel decriptionLabel = new JLabel(); 61 decriptionLabel.setBorder(BorderFactory.createTitledBorder("Description")); 62 decriptionLabel.setText("This step shows the license for the product."); 63 contraint.fill = GridBagConstraints.BOTH; 64 contraint.insets = new Insets(16,16,0,16); 65 contraint.anchor = GridBagConstraints.WEST; 66 contraint.gridx = 0; 67 contraint.gridy = 0; 68 contraint.gridwidth = 3; 69 contraint.gridheight = 1; 70 contraint.weightx = 1; 71 contraint.weighty = 0; 72 layout.setConstraints(decriptionLabel,contraint); 73 add(decriptionLabel); 74 75 JLabel licenseFileNameLabel = new JLabel(); 77 licenseFileNameLabel.setText("Filename of license file:"); 78 contraint.fill = GridBagConstraints.BOTH; 79 contraint.insets = new Insets(16,16,0,16); 80 contraint.anchor = GridBagConstraints.WEST; 81 contraint.gridx = 0; 82 contraint.gridy = 1; 83 contraint.gridwidth = 2; 84 contraint.gridheight = 1; 85 contraint.weightx = 1; 86 contraint.weighty = 0; 87 layout.setConstraints(licenseFileNameLabel,contraint); 88 add(licenseFileNameLabel); 89 90 licenseFileNameField = new RequiredTextField(); 91 licenseFileNameField.setEditable(false); 92 licenseFileNameField.setColumns(40); 93 contraint.fill = GridBagConstraints.NONE; 94 contraint.insets = new Insets(16,16,0,16); 95 contraint.anchor = GridBagConstraints.WEST; 96 contraint.gridx = 0; 97 contraint.gridy = 2; 98 contraint.gridwidth = 2; 99 contraint.gridheight = 1; 100 contraint.weightx = 0; 101 contraint.weighty = 0; 102 layout.setConstraints(licenseFileNameField,contraint); 103 add(licenseFileNameField); 104 105 licenseFileNameButton = new JButton(); 106 licenseFileNameButton.setText("Change"); 107 licenseFileNameButton.setMnemonic('C'); 108 licenseFileNameButton.setSize(licenseFileNameButton.getSize().width,licenseFileNameField.getSize().height); 109 licenseFileNameButton.addActionListener(this); 110 contraint.fill = GridBagConstraints.NONE; 111 contraint.insets = new Insets(16,0,0,16); 112 contraint.anchor = GridBagConstraints.WEST; 113 contraint.gridx = 2; 114 contraint.gridy = 2; 115 contraint.gridwidth = 1; 116 contraint.gridheight = 1; 117 contraint.weightx = 0; 118 contraint.weighty = 0; 119 layout.setConstraints(licenseFileNameButton,contraint); 120 add(licenseFileNameButton); 121 122 JLabel encodingLabel = new JLabel(); 124 encodingLabel.setText("Encoding of license file:"); 125 contraint.fill = GridBagConstraints.BOTH; 126 contraint.insets = new Insets(16,16,0,16); 127 contraint.anchor = GridBagConstraints.WEST; 128 contraint.gridx = 0; 129 contraint.gridy = 3; 130 contraint.gridwidth = 2; 131 contraint.gridheight = 1; 132 contraint.weightx = 1; 133 contraint.weighty = 0; 134 layout.setConstraints(encodingLabel,contraint); 135 add(encodingLabel); 136 137 encodingField = new JTextField(); 138 encodingField.addFocusListener(this); 139 encodingField.setColumns(12); 140 contraint.fill = GridBagConstraints.HORIZONTAL; 141 contraint.insets = new Insets(16,16,0,16); 142 contraint.anchor = GridBagConstraints.WEST; 143 contraint.gridx = 0; 144 contraint.gridy = 4; 145 contraint.gridwidth = 1; 146 contraint.gridheight = 1; 147 contraint.weightx = 0; 148 contraint.weighty = 0; 149 layout.setConstraints(encodingField,contraint); 150 add(encodingField); 151 152 JPanel fillPanel = new JPanel(); 153 contraint.fill = GridBagConstraints.BOTH; 154 contraint.insets = new Insets(4,4,4,4); 155 contraint.anchor = GridBagConstraints.CENTER; 156 contraint.gridx = 3; 157 contraint.gridy = 5; 158 contraint.gridwidth = 1; 159 contraint.gridheight = 1; 160 contraint.weightx = 1; 161 contraint.weighty = 1; 162 layout.setConstraints(fillPanel,contraint); 163 add(fillPanel); 164 165 } 166 167 168 171 public void save() { 172 } 173 174 177 public void initialize(VAIProductModel model) { 178 this.model = model; 179 180 licenseFileNameField.addFocusListener(this); 181 licenseFileNameField.initialize(model,"License File"); 182 183 if (model.getLicenseName() != null) { 184 licenseFileNameField.setText(model.getLicenseName()); 185 } 186 if (model.getLicenseEncoding() != null) { 187 encodingField.setText(model.getLicenseEncoding()); 188 } 189 190 } 191 192 195 public void stop() { 196 } 197 198 202 public void actionPerformed(ActionEvent evt) { 203 try { 204 205 Object source = evt.getSource(); 207 208 if (source == licenseFileNameButton) { 209 210 JFileChooser jfc = new JFileChooser(); 212 jfc.setDialogType(JFileChooser.OPEN_DIALOG); 213 jfc.setFileSelectionMode(JFileChooser.FILES_ONLY); 214 215 String rootDirectory = (String )model.getPropertyList().get("vainstall.user.dir"); 216 if (rootDirectory == null) { 217 rootDirectory = System.getProperty("user.dir"); 218 } 219 220 jfc.setCurrentDirectory(new File (rootDirectory)); 221 222 int result = jfc.showDialog(new JFrame(),"Select License File"); 223 if (result == JFileChooser.APPROVE_OPTION) { 224 licenseFileNameField.setText(jfc.getSelectedFile().getAbsolutePath()); 225 226 model.getPropertyList().put("vainstall.user.dir",jfc.getCurrentDirectory().getAbsolutePath()); 227 228 model.setLicenseName(jfc.getSelectedFile().getAbsolutePath()); 230 } 231 } 232 233 } catch(Exception exc) { 234 return; 237 } 238 } 239 240 public void focusGained(FocusEvent evt) { 241 } 242 243 public void focusLost(FocusEvent evt) { 244 if (evt.getSource() == encodingField) { 245 if (encodingField.getText().length() > 0) { 246 model.setLicenseEncoding(encodingField.getText()); 247 } 248 } 249 } 250 } 251 | Popular Tags |