Guest User

Untitled

a guest
Mar 1st, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.37 KB | None | 0 0
  1. public class RegisterContentCreator extends FormSheetContentCreator {
  2. private JTextArea errorMessage;
  3. private JLabel message;
  4. private JTextField userName;
  5. private JPasswordField password;
  6. private JPasswordField confirmedPassword;
  7. private JFileChooser fcImage = null;
  8. private ImagePanel ImageView;
  9. private JLabel jahr;
  10. private JLabel tag;
  11. private JLabel monat;
  12. private Integer[] jahrboxitem = {1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996};
  13. private Integer[] tagboxitem = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31};
  14. private Integer[] monatboxitem = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
  15. private JComboBox jahrbox;
  16. private JComboBox tagbox;
  17. private JComboBox monatbox;
  18.  
  19.  
  20. public RegisterContentCreator(String message) {
  21. errorMessage = new JTextArea();
  22. this.message = new JLabel();
  23. userName = new JTextField();
  24. password = new JPasswordField();
  25. jahr = new JLabel("Geburtsjahr");
  26. jahrbox = new JComboBox(jahrboxitem);
  27. tag = new JLabel("Geburtstag");
  28. tagbox = new JComboBox(tagboxitem);
  29. monat = new JLabel("Geburtsmonat");
  30. monatbox = new JComboBox(monatboxitem);
  31. confirmedPassword = new JPasswordField();
  32. this.message.setText(message);
  33. errorMessage.setForeground(Color.RED);
  34. errorMessage.setBackground(this.message.getBackground());
  35. errorMessage.setEditable(false);
  36. ImageView = new ImagePanel();
  37. fcImage = new JFileChooser();
  38. fcImage.setFileFilter(new FileFilter() {
  39.  
  40. @Override
  41. public boolean accept(File f) {
  42. if (f.isDirectory())
  43. return true;
  44. String[] xts = new String[] { "jpg", "jpeg", "png", "gif",
  45. "bmp" };
  46. for (String xt : xts)
  47. if (f.getPath().toLowerCase().endsWith("." + xt))
  48. return true;
  49. return false;
  50. }
  51.  
  52. @Override
  53. public String getDescription() {
  54. return "Images";
  55. }
  56.  
  57. });
  58. }
  59.  
  60. @Override
  61. protected void createFormSheetContent(FormSheet fs) {
  62. JPanel superpanel = new JPanel(new BorderLayout());
  63. JOptionPanel panel = new JOptionPanel(null, 16, 4, JOptionPanel.CENTER,
  64. JOptionPanel.CENTER);
  65.  
  66. userName.setPreferredSize(new Dimension(150, 27));
  67. panel.addOption("Nutzername", userName);
  68.  
  69. panel.add(jahr);
  70. panel.add(jahrbox);
  71.  
  72. panel.add(tag);
  73. panel.add(tagbox);
  74.  
  75. panel.add(monat);
  76. panel.add(monatbox);
  77.  
  78. password.setEchoChar('\u2022');
  79. password.setPreferredSize(new Dimension(150, 27));
  80. panel.addOption("Passwort", password);
  81.  
  82. confirmedPassword.setEchoChar('\u2022');
  83. confirmedPassword.setPreferredSize(new Dimension(150, 27));
  84. panel.addOption("Passwort bestätigen", confirmedPassword);
  85.  
  86. errorMessage.setPreferredSize(new Dimension(300, 27));
  87. errorMessage.setBackground(new Color(0, 0, 0, 0));
  88. errorMessage.setOpaque(false);
  89. errorMessage.setBorder(BorderFactory.createEmptyBorder());
  90. panel.addOption("", errorMessage);
  91.  
  92. JButton btnImage = new JButton("Bild auswaehlen...");
  93. final JTextField ImageField = new JTextField();
  94. ImageField.setPreferredSize(new Dimension(150, 27));
  95. final JFileChooser fFcImage = fcImage;
  96. btnImage.addActionListener(new ActionListener() {
  97.  
  98. public void actionPerformed(ActionEvent e) {
  99. if (fFcImage.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
  100. try {
  101. ImageField.setText(fFcImage.getSelectedFile()
  102. .getCanonicalFile().toURI().toString());
  103. ImageView.setImage(ImageIO.read(fFcImage
  104. .getSelectedFile().getCanonicalFile()), true);
  105. } catch (IOException e1) {
  106. e1.printStackTrace();
  107. }
  108. }
  109. }
  110. });
  111. ImageView.setPreferredSize(new Dimension(150, 150));
  112. try {
  113. ImageView.setImage(ImageIO.read(new URL(User.defaultUserImage)),
  114. true);
  115. } catch (MalformedURLException e1) {
  116. // TODO Auto-generated catch block
  117. e1.printStackTrace();
  118. } catch (IOException e1) {
  119. // TODO Auto-generated catch block
  120. e1.printStackTrace();
  121. }
  122.  
  123. panel.addOption("", btnImage);
  124. panel.addOption("", ImageField);
  125. JPanel imageContainer = new JPanel(new GridBagLayout());
  126. GridBagConstraints ctr = new GridBagConstraints();
  127. ctr.insets = new Insets(25, 25, 0, 25);
  128. ctr.anchor = GridBagConstraints.NORTH;
  129. ctr.weighty = 1f;
  130. imageContainer.setBackground(new Color(51, 84, 111, 150));
  131. imageContainer.add(ImageView, ctr);
  132. panel.setOpaque(false);
  133. superpanel.add(panel, BorderLayout.CENTER);
  134. superpanel.add(imageContainer, BorderLayout.EAST);
  135. fs.setComponent(superpanel);
  136. fs.removeAllButtons();
  137. fs.addButton("OK", 1, new TransitWithAction(new RegisterOKTransition(
  138. this)));
  139. fs.addButton("Abbruch", 2, new RollBackAction());
  140. }
  141.  
  142. public String getUserName() {
  143. return userName.getText();
  144. }
  145.  
  146. public String getPassword() {
  147. return String.valueOf(password.getPassword());
  148. }
  149.  
  150. public String getConfirmedPassword() {
  151. return String.valueOf(confirmedPassword.getPassword());
  152. }
  153.  
  154.  
  155. public Date getGebDat() {
  156. return new Date(jahrbox.getSelectedIndex(), monatbox.getSelectedIndex(), tagbox.getSelectedIndex());
  157. }
  158.  
  159. public URI getUserImage() {
  160. if (fcImage.getSelectedFile() == null)
  161. return null;
  162. return fcImage.getSelectedFile().toURI();
  163. }
  164.  
  165. public void setUserName(String userName) {
  166. this.userName.setText(userName);
  167. }
  168.  
  169. public void setErrorMessage(String message) {
  170. errorMessage.setText(message);
  171. }
  172.  
  173. }
Add Comment
Please, Sign In to add comment