001 package videoautomat.contentcreator; 002 import java.awt.Color; 003 import java.awt.Dimension; 004 005 import javax.swing.JLabel; 006 import javax.swing.JPasswordField; 007 import javax.swing.JTextArea; 008 import javax.swing.JTextField; 009 010 import sale.FormSheet; 011 import sale.FormSheetContentCreator; 012 import util.swing.JOptionPanel; 013 import videoautomat.contentcreator.stdactions.RollBackAction; 014 import videoautomat.contentcreator.stdactions.TransitWithAction; 015 import videoautomat.transition.RegisterOKTransition; 016 017 /** 018 * Content creator of the register process. Contains methods to set and add data 019 * independly from the gui part. 020 * 021 * @author Tobias Ruch 022 */ 023 public class RegisterContentCreator extends FormSheetContentCreator { 024 025 /** 026 * ID for Serialization. 027 */ 028 private static final long serialVersionUID = -5026365424912142706L; 029 /** Textarea for the error message */ 030 private JTextArea errorMessage; 031 /** Label with the initial massage */ 032 private JLabel message; 033 /** Textfield for the user name */ 034 private JTextField userName; 035 /** PasswordField for the 1st password */ 036 private JPasswordField password; 037 /** PasswordField for the 2nd password */ 038 private JPasswordField confirmedPassword; 039 /** 040 * Creates a new content creator with an initial message 041 * @param message - initial message 042 */ 043 public RegisterContentCreator(String message){ 044 045 //initialize components 046 errorMessage = new JTextArea(); 047 this.message = new JLabel(); 048 userName = new JTextField(); 049 password = new JPasswordField(); 050 confirmedPassword = new JPasswordField(); 051 //set initial values 052 this.message.setText(message); 053 errorMessage.setForeground(Color.RED); 054 errorMessage.setBackground(this.message.getBackground()); 055 errorMessage.setEditable(false); 056 } 057 058 /** 059 * Method will be called from the FormSheet to which this ContentCreator is added. 060 * So the Attribut fs will be this FormSheet. 061 * You have to bild the content of your formsheet in this method 062 * @param fs - FormSheet to which this ContentCreator was added. 063 */ 064 protected void createFormSheetContent(FormSheet fs) { 065 JOptionPanel panel = new JOptionPanel(null, 16, 4, JOptionPanel.CENTER, JOptionPanel.CENTER); 066 067 userName.setPreferredSize(new Dimension(150, 20)); 068 panel.addOption("User Name", userName); 069 070 password.setPreferredSize(new Dimension(150, 20)); 071 panel.addOption("Password", password); 072 073 confirmedPassword.setPreferredSize(new Dimension(150, 20)); 074 panel.addOption("Confirm Password", confirmedPassword); 075 076 errorMessage.setPreferredSize(new Dimension(200, 50)); 077 panel.addOption("", errorMessage); 078 fs.setComponent(panel); 079 080 // set Buttons; using standard action to set transition classes 081 fs.removeAllButtons(); 082 fs.addButton("OK", 1, new TransitWithAction(new RegisterOKTransition(this))); 083 fs.addButton("Cancel", 2, new RollBackAction()); 084 } 085 086 087 /** 088 * Returns the value of the username. 089 * @return - the username 090 */ 091 public String getUserName(){ 092 return userName.getText(); 093 } 094 095 /** 096 * Returns the value of the password. 097 * @return - the value of the password as an char array 098 */ 099 public char[] getPassword(){ 100 return password.getPassword(); 101 } 102 103 /** 104 * Returns the value of the confirmed password. 105 * @return - the value of the password as an char array 106 */ 107 public char[] getConfirmedPassword(){ 108 return confirmedPassword.getPassword(); 109 } 110 111 /** 112 * Sets the value of the username 113 * @param userName - value of the username 114 */ 115 public void setUserName(String userName){ 116 this.userName.setText(userName); 117 } 118 119 /** 120 * Sets the error message to this formsheet. 121 * @param message - an error massage. 122 */ 123 public void setErrorMessage(String message){ 124 errorMessage.setText(message); 125 } 126 127 }