public Visitor getVisitor() { Visitor visitor = new Visitor(); visitor.setFirst_name(this.getTfFirstName().getText().toString().trim()); visitor.setPatronymic(this.getTfMiddleName().getText().toString().trim()); visitor.setSurname(this.getTfSureName().getText().toString().trim()); if (rbtnMale.isSelected()) visitor.setSex("мужчина"); if (rbtnFemale.isSelected()) visitor.setSex("женщина"); visitor.setAdress(this.getTfAdress().getText().toString().trim()); visitor.setBirthday(this.getTfBirthDay().getText().toString().trim()); visitor.setNumber_phone(this.getTfNumberPhone().getText().toString().trim()); visitor.setIndexCard(cbCard.getSelectedIndex() + 1); visitor.setCard(cbCard.getSelectedItem().toString().trim()); visitor.setKey(0); visitor.setNotation(this.getNotation().getText().toString().trim()); visitor.setDate_reg(this.getTfDateReg().getText().toString().trim()); visitor.setBalance(this.getTfBalance().getText().toString().trim()); visitor.setPhoto(this.fileImage); return visitor; }
private void prepareDialog(Visitor visitor) { listener = new VisitorPersonalListener(); lbFirstName = new JLabel("имя:"); lbFirstName.setBounds(10, 209, 70, 10); tfFirstName = new JTextField(); tfFirstName.setBounds(80, 205, 110, 20); lbMiddleName = new JLabel("отчество:"); lbMiddleName.setBounds(10, 230, 70, 10); tfMiddleName = new JTextField(); tfMiddleName.setBounds(80, 225, 110, 20); lbSureName = new JLabel("фамилия:"); lbSureName.setBounds(10, 248, 70, 15); tfSureName = new JTextField(); tfSureName.setBounds(80, 245, 110, 20); lbBirthDay = new JLabel("д.рож.:"); lbBirthDay.setBounds(10, 273, 70, 15); tfBirthDay = new JTextField(); tfBirthDay.setBounds(80, 270, 110, 20); tfBirthDay.addKeyListener(listener); lbAdress = new JLabel("адресс:"); lbAdress.setBounds(10, 298, 70, 15); tfAdress = new JTextField(); tfAdress.setBounds(80, 295, 110, 20); lbNumberPhone = new JLabel("№ тел.:"); lbNumberPhone.setBounds(10, 325, 70, 15); tfNumberPhone = new JTextField(); tfNumberPhone.setBounds(80, 325, 110, 20); lbDateReg = new JLabel("д.регист.:"); lbDateReg.setBounds(9, 350, 75, 15); tfDateReg = new JTextField(); tfDateReg.setBounds(81, 350, 110, 20); tfDateReg.addKeyListener(listener); lbCard = new JLabel("карта:"); lbCard.setBounds(10, 375, 70, 15); String[] arCard = new String[dbManager.getAllCards().size()]; for (int i = 0; i < arCard.length; i++) { arCard[i] = dbManager.getAllCards().get(i).getCard(); } cbCard = new JComboBox<String>(arCard); cbCard.setBounds(80, 375, 110, 20); lbBalance = new JLabel("баланс:"); lbBalance.setBounds(10, 400, 70, 15); tfBalance = new JTextField(); tfBalance.setBounds(80, 400, 110, 20); lbDiscount = new JLabel("скидки:"); lbDiscount.setBounds(10, 425, 70, 15); tfDiscount = new JTextField(); tfDiscount.setBounds(80, 425, 110, 20); sexButtonGroup = new ButtonGroup(); rbtnMale = new JRadioButton("муж."); rbtnMale.setBounds(10, 450, 70, 20); rbtnFemale = new JRadioButton("жен."); rbtnFemale.setBounds(90, 450, 70, 20); sexButtonGroup.add(rbtnMale); sexButtonGroup.add(rbtnFemale); notation = new JTextArea(); notation.setLineWrap(true); scroll = new JScrollPane( notation, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scroll.setBounds(10, 480, 180, 50); westPanel = new JPanel(); westPanel.setFocusable(false); westPanel.setPreferredSize(new Dimension(200, 400)); westPanel.setLayout(null); photo = new JLabel(); photo.setName("photo"); photo.addMouseListener(listener); if (visitor == null) { image = new ImageIcon(StartAplication.class.getClass().getResource("/visitor.png")); photo.setIcon(this.scaleImage(image)); photo.setBounds(10, 10, 180, 180); photo.setBorder(BorderFactory.createEtchedBorder()); } else { this.setVisitorId(visitor.getId()); tfFirstName.setText(visitor.getFirst_name().toString()); tfMiddleName.setText(visitor.getPatronymic().toString()); tfSureName.setText(visitor.getSurname().toString()); tfBirthDay.setText(visitor.getBirthday().toString()); tfAdress.setText(visitor.getAdress().toString()); if (visitor.getSex().equals("мужчина")) rbtnMale.setSelected(true); if (visitor.getSex().equals("женщина")) rbtnFemale.setSelected(true); tfNumberPhone.setText(visitor.getNumber_phone() + ""); tfDateReg.setText(visitor.getData_reg().toString()); cbCard.setSelectedIndex(visitor.getIndexCard() - 1); tfBalance.setText(visitor.getBalance() + ""); tfDiscount.setText("уточнять"); notation.setText(visitor.getNotation().toString()); if ((visitor.getPhoto().toString()).equals(null) || (visitor.getPhoto().toString()).equals("---") || (visitor.getPhoto().toString()).equals("")) { image = new ImageIcon(StartAplication.class.getClass().getResource("/visitor.png")); } else { fileImage = visitor.getPhoto().toString(); image = new ImageIcon(fileImage); } photo.setIcon(this.scaleImage(image)); photo.setBounds(10, 10, 180, 180); photo.setBorder(BorderFactory.createEtchedBorder()); } JSeparator separator = new JSeparator(JSeparator.HORIZONTAL); separator.setBounds(0, 200, 200, 1); westPanel.add(photo); westPanel.add(separator); westPanel.add(lbFirstName); westPanel.add(tfFirstName); westPanel.add(lbMiddleName); westPanel.add(tfMiddleName); westPanel.add(lbSureName); westPanel.add(tfSureName); westPanel.add(lbBirthDay); westPanel.add(tfBirthDay); westPanel.add(lbAdress); westPanel.add(tfAdress); westPanel.add(lbNumberPhone); westPanel.add(tfNumberPhone); westPanel.add(lbDateReg); westPanel.add(tfDateReg); westPanel.add(lbCard); westPanel.add(cbCard); westPanel.add(lbBalance); westPanel.add(tfBalance); westPanel.add(lbDiscount); westPanel.add(tfDiscount); westPanel.add(rbtnMale); westPanel.add(rbtnFemale); westPanel.add(scroll); abovePanel = new JPanel(); abovePanel.setPreferredSize(new Dimension(50, 50)); model = new DefaultTableModel(AppUtills.PERSONAL_TABLE_COLUMN_NAME, 1); if (visitor != null) { List<BookService> listBookService = dbManager.getBookServiceByVisitorId(visitor.getId()); for (int row = 0; row < listBookService.size(); row++) { int column = 0; BookService tmp = listBookService.get(row); model.addRow(new Vector<String>()); model.setValueAt(tmp.getId(), row, column++); model.setValueAt(tmp.getService(), row, column++); model.setValueAt(tmp.getDate(), row, column++); model.setValueAt(tmp.getStaff(), row, column++); model.setValueAt(tmp.getNotation(), row, column); } } personalTableService = new JTable(model) { @Override public boolean isCellEditable(int row, int column) { return false; } }; personalTableService.setName("personalTableBookService"); personalTableService.getColumnModel().getColumn(0).setMaxWidth(50); personalTableService.getColumnModel().getColumn(2).setMaxWidth(80); personalTableService.addMouseListener(listener); JScrollPane scroll = new JScrollPane( personalTableService, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); centerPanel = new JPanel(); centerPanel.setLayout(new GridLayout(1, 1)); centerPanel.add(scroll); centerPanel.setBackground(Color.RED); centerPanel.setPreferredSize(new Dimension(50, 50)); JButton btnSave = new JButton("сохранить"); btnSave.setToolTipText("сохранить нового посетителя"); btnSave.addActionListener(listener); JButton btnCancel = new JButton("отмена"); btnCancel.setToolTipText("закрыть без сохраниения"); btnCancel.addActionListener(listener); bottomPanel = new JPanel(); bottomPanel.add(btnSave); bottomPanel.add(btnCancel); bottomPanel.setPreferredSize(new Dimension(50, 50)); infoPanel = new JPanel(); infoPanel.setLayout(new BorderLayout()); infoPanel.add(abovePanel, BorderLayout.NORTH); infoPanel.add(centerPanel, BorderLayout.CENTER); infoPanel.add(bottomPanel, BorderLayout.SOUTH); dialog = new JDialog(); dialog.setAlwaysOnTop(true); dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); dialog.setSize(850, 550); dialog.setResizable(false); dialog.setLayout(new BorderLayout()); dialog.getContentPane().add(westPanel, BorderLayout.WEST); dialog.getContentPane().add(infoPanel, BorderLayout.CENTER); dialog.setVisible(true); }