Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class RegisterContentCreator extends FormSheetContentCreator {
- private JTextArea errorMessage;
- private JLabel message;
- private JTextField userName;
- private JPasswordField password;
- private JPasswordField confirmedPassword;
- private JFileChooser fcImage = null;
- private ImagePanel ImageView;
- private JLabel jahr;
- private JLabel tag;
- private JLabel monat;
- private Integer[] jahrboxitem = {1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996};
- 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};
- private Integer[] monatboxitem = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
- private JComboBox jahrbox;
- private JComboBox tagbox;
- private JComboBox monatbox;
- public RegisterContentCreator(String message) {
- errorMessage = new JTextArea();
- this.message = new JLabel();
- userName = new JTextField();
- password = new JPasswordField();
- jahr = new JLabel("Geburtsjahr");
- jahrbox = new JComboBox(jahrboxitem);
- tag = new JLabel("Geburtstag");
- tagbox = new JComboBox(tagboxitem);
- monat = new JLabel("Geburtsmonat");
- monatbox = new JComboBox(monatboxitem);
- confirmedPassword = new JPasswordField();
- this.message.setText(message);
- errorMessage.setForeground(Color.RED);
- errorMessage.setBackground(this.message.getBackground());
- errorMessage.setEditable(false);
- ImageView = new ImagePanel();
- fcImage = new JFileChooser();
- fcImage.setFileFilter(new FileFilter() {
- @Override
- public boolean accept(File f) {
- if (f.isDirectory())
- return true;
- String[] xts = new String[] { "jpg", "jpeg", "png", "gif",
- "bmp" };
- for (String xt : xts)
- if (f.getPath().toLowerCase().endsWith("." + xt))
- return true;
- return false;
- }
- @Override
- public String getDescription() {
- return "Images";
- }
- });
- }
- @Override
- protected void createFormSheetContent(FormSheet fs) {
- JPanel superpanel = new JPanel(new BorderLayout());
- JOptionPanel panel = new JOptionPanel(null, 16, 4, JOptionPanel.CENTER,
- JOptionPanel.CENTER);
- userName.setPreferredSize(new Dimension(150, 27));
- panel.addOption("Nutzername", userName);
- panel.add(jahr);
- panel.add(jahrbox);
- panel.add(tag);
- panel.add(tagbox);
- panel.add(monat);
- panel.add(monatbox);
- password.setEchoChar('\u2022');
- password.setPreferredSize(new Dimension(150, 27));
- panel.addOption("Passwort", password);
- confirmedPassword.setEchoChar('\u2022');
- confirmedPassword.setPreferredSize(new Dimension(150, 27));
- panel.addOption("Passwort bestätigen", confirmedPassword);
- errorMessage.setPreferredSize(new Dimension(300, 27));
- errorMessage.setBackground(new Color(0, 0, 0, 0));
- errorMessage.setOpaque(false);
- errorMessage.setBorder(BorderFactory.createEmptyBorder());
- panel.addOption("", errorMessage);
- JButton btnImage = new JButton("Bild auswaehlen...");
- final JTextField ImageField = new JTextField();
- ImageField.setPreferredSize(new Dimension(150, 27));
- final JFileChooser fFcImage = fcImage;
- btnImage.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- if (fFcImage.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
- try {
- ImageField.setText(fFcImage.getSelectedFile()
- .getCanonicalFile().toURI().toString());
- ImageView.setImage(ImageIO.read(fFcImage
- .getSelectedFile().getCanonicalFile()), true);
- } catch (IOException e1) {
- e1.printStackTrace();
- }
- }
- }
- });
- ImageView.setPreferredSize(new Dimension(150, 150));
- try {
- ImageView.setImage(ImageIO.read(new URL(User.defaultUserImage)),
- true);
- } catch (MalformedURLException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- } catch (IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- panel.addOption("", btnImage);
- panel.addOption("", ImageField);
- JPanel imageContainer = new JPanel(new GridBagLayout());
- GridBagConstraints ctr = new GridBagConstraints();
- ctr.insets = new Insets(25, 25, 0, 25);
- ctr.anchor = GridBagConstraints.NORTH;
- ctr.weighty = 1f;
- imageContainer.setBackground(new Color(51, 84, 111, 150));
- imageContainer.add(ImageView, ctr);
- panel.setOpaque(false);
- superpanel.add(panel, BorderLayout.CENTER);
- superpanel.add(imageContainer, BorderLayout.EAST);
- fs.setComponent(superpanel);
- fs.removeAllButtons();
- fs.addButton("OK", 1, new TransitWithAction(new RegisterOKTransition(
- this)));
- fs.addButton("Abbruch", 2, new RollBackAction());
- }
- public String getUserName() {
- return userName.getText();
- }
- public String getPassword() {
- return String.valueOf(password.getPassword());
- }
- public String getConfirmedPassword() {
- return String.valueOf(confirmedPassword.getPassword());
- }
- public Date getGebDat() {
- return new Date(jahrbox.getSelectedIndex(), monatbox.getSelectedIndex(), tagbox.getSelectedIndex());
- }
- public URI getUserImage() {
- if (fcImage.getSelectedFile() == null)
- return null;
- return fcImage.getSelectedFile().toURI();
- }
- public void setUserName(String userName) {
- this.userName.setText(userName);
- }
- public void setErrorMessage(String message) {
- errorMessage.setText(message);
- }
- }
Add Comment
Please, Sign In to add comment