Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Frame;
- import javax.swing.JFrame;
- import javax.swing.JOptionPane;
- import java.util.ArrayList;
- import javax.swing.GroupLayout;
- import javax.swing.GroupLayout.Alignment;
- import javax.swing.JComboBox;
- import javax.swing.JTextField;
- import javax.swing.LayoutStyle.ComponentPlacement;
- import javax.swing.table.DefaultTableModel;
- import Model.*;
- import Panels.*;
- import javax.swing.JTextPane;
- import javax.swing.JTextArea;
- import javax.swing.JButton;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- import javax.swing.JScrollPane;
- import javax.swing.JTable;
- import java.awt.Color;
- import java.awt.Font;
- import javax.swing.SwingConstants;
- public class OfferFrame extends JFrame {
- public ArrayList<Company> companies = new ArrayList<Company>();
- public ArrayList<Offer> offers = new ArrayList<Offer>();
- public ArrayList<Tipes> tipes = new ArrayList<Tipes>();
- public ArrayList<Offer> searchOffers;
- public ArrayList<Offer> selectedCompany;
- public CandidatePanel candidatePanel;
- public boolean isFiltering = false;
- private JTextField positionField;
- private JComboBox companyComboBox;
- private JComboBox tipeComboBox;
- private JTextArea descriptionTextView;
- private JButton addOfferButton;
- private JTable table;
- public DefaultTableModel tableModel;
- private JButton removeButton;
- private JButton candidateButton;
- private JButton searchButton;
- private JTextField searchField;
- private JButton selectedSearchButton;
- public OfferFrame(ArrayList<Company> companies, ArrayList<Tipes> tipes) {
- super("Job Offerts");
- setDefaultCloseOperation(EXIT_ON_CLOSE);
- setSize(800, 600);
- this.companies = companies;
- this.tipes = tipes;
- companyComboBox = new JComboBox();
- for (Company companie : companies) {
- companyComboBox.addItem(companie.name);
- }
- positionField = new JTextField("position");
- positionField.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent e) {
- positionField.setText("");
- }
- });
- positionField.setColumns(10);
- tipeComboBox = new JComboBox();
- for (Tipes tipes2 : tipes) {
- tipeComboBox.addItem(tipes2.name);
- }
- descriptionTextView = new JTextArea();
- descriptionTextView.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent e) {
- descriptionTextView.setText("");
- }
- });
- descriptionTextView.setText("Descriptiion min 100 characters");
- JButton addOfferButton = new JButton("Add");
- addOfferButton.setForeground(Color.GREEN);
- addOfferButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- checkField();
- }
- });
- JScrollPane scrollPane = new JScrollPane();
- removeButton = new JButton("Remove");
- removeButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- offers.remove(table.getSelectedRow());
- refreshTabled();
- }
- });
- removeButton.setForeground(Color.RED);
- candidateButton = new JButton("Candidate");
- candidateButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- showPanel();
- }
- });
- candidateButton.setFont(new Font("Tahoma", Font.BOLD, 24));
- candidateButton.setForeground(Color.ORANGE);
- searchButton = new JButton("Search");
- searchButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- filterOffersByPosition();
- }
- });
- searchButton.setForeground(Color.BLUE);
- searchButton.setFont(new Font("Tahoma", Font.BOLD, 24));
- searchField = new JTextField();
- searchField.addMouseListener(new MouseAdapter() {
- @Override
- public void mouseClicked(MouseEvent e) {
- searchField.setText("");
- }
- });
- searchField.setHorizontalAlignment(SwingConstants.CENTER);
- searchField.setText("Search");
- searchField.setColumns(10);
- selectedSearchButton = new JButton("selectedsearch");
- selectedSearchButton.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- selectCompany();
- }
- });
- GroupLayout groupLayout = new GroupLayout(getContentPane());
- groupLayout.setHorizontalGroup(
- groupLayout.createParallelGroup(Alignment.LEADING)
- .addGroup(groupLayout.createSequentialGroup()
- .addContainerGap()
- .addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
- .addGroup(groupLayout.createSequentialGroup()
- .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
- .addGroup(groupLayout.createSequentialGroup()
- .addComponent(addOfferButton, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(ComponentPlacement.RELATED, 38, Short.MAX_VALUE)
- .addComponent(removeButton, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE))
- .addComponent(tipeComboBox, 0, 238, Short.MAX_VALUE)
- .addComponent(descriptionTextView, GroupLayout.PREFERRED_SIZE, 238, Short.MAX_VALUE)
- .addComponent(positionField, GroupLayout.DEFAULT_SIZE, 238, Short.MAX_VALUE)
- .addComponent(companyComboBox, 0, 238, Short.MAX_VALUE))
- .addGap(32)
- .addComponent(selectedSearchButton, GroupLayout.PREFERRED_SIZE, 176, GroupLayout.PREFERRED_SIZE)
- .addGap(29)
- .addGroup(groupLayout.createParallelGroup(Alignment.TRAILING, false)
- .addComponent(searchButton, GroupLayout.DEFAULT_SIZE, 280, Short.MAX_VALUE)
- .addComponent(candidateButton, GroupLayout.DEFAULT_SIZE, 280, Short.MAX_VALUE)
- .addComponent(searchField)))
- .addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 746, GroupLayout.PREFERRED_SIZE))
- .addGap(19))
- );
- groupLayout.setVerticalGroup(
- groupLayout.createParallelGroup(Alignment.TRAILING)
- .addGroup(groupLayout.createSequentialGroup()
- .addGap(41)
- .addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 247, GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(ComponentPlacement.RELATED, 31, Short.MAX_VALUE)
- .addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
- .addGroup(groupLayout.createSequentialGroup()
- .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
- .addComponent(companyComboBox, GroupLayout.PREFERRED_SIZE, 31, GroupLayout.PREFERRED_SIZE)
- .addComponent(selectedSearchButton, GroupLayout.PREFERRED_SIZE, 24, GroupLayout.PREFERRED_SIZE))
- .addPreferredGap(ComponentPlacement.RELATED)
- .addComponent(positionField, GroupLayout.PREFERRED_SIZE, 29, GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(ComponentPlacement.RELATED)
- .addComponent(tipeComboBox, GroupLayout.PREFERRED_SIZE, 32, GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(ComponentPlacement.RELATED)
- .addComponent(descriptionTextView, GroupLayout.PREFERRED_SIZE, 80, GroupLayout.PREFERRED_SIZE)
- .addGap(18)
- .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
- .addComponent(addOfferButton)
- .addComponent(removeButton))
- .addContainerGap())
- .addGroup(groupLayout.createSequentialGroup()
- .addComponent(searchField, GroupLayout.PREFERRED_SIZE, 39, GroupLayout.PREFERRED_SIZE)
- .addGap(18)
- .addComponent(searchButton, GroupLayout.PREFERRED_SIZE, 41, GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(ComponentPlacement.UNRELATED)
- .addComponent(candidateButton, GroupLayout.PREFERRED_SIZE, 86, GroupLayout.PREFERRED_SIZE)
- .addGap(38))))
- );
- table = new JTable();
- String collums[] = { "Фирма", "Позиция", "Тип", "Описание", "Брой кандидати" };
- tableModel = new DefaultTableModel();
- tableModel.setColumnIdentifiers(collums);
- table.setModel(tableModel);
- scrollPane.setViewportView(table);
- getContentPane().setLayout(groupLayout);
- }
- public void addOfferAction() {
- Company company = companies.get(companyComboBox.getSelectedIndex());
- Tipes tipe = tipes.get(tipeComboBox.getSelectedIndex());
- Offer a = new Offer(company, positionField.getText().toLowerCase(), tipe, descriptionTextView.getText());
- offers.add(a);
- refreshTable();
- }
- public void filterOffersByPosition() {
- searchOffers = new ArrayList<Offer>();
- isFiltering = false;
- String a = searchField.getText().toLowerCase();
- for (Offer offer : offers) {
- if (offer.position.contains(a.toLowerCase())) {
- searchOffers.add(offer);
- isFiltering = true;
- refreshTabled();
- }
- }
- }
- public void selectCompany() {
- selectedCompany = new ArrayList<Offer>();
- //isFiltering = false;
- Company compani = companies.get(table.getSelectedRow());
- for (Offer offer : offers) {
- if(compani.companyID == offer.company.companyID) {
- selectedCompany.add(offer);
- isFiltering = true;
- refreshTabled();
- }
- }
- }
- public void refreshTable() {
- tableModel.setRowCount(0);
- for (Offer offer : offers) {
- Object row[] = new Object[5];
- row[0] = offer.company.name;
- row[1] = offer.position;
- row[2] = offer.tipes.name;
- row[3] = offer.descriptions;
- row[4] = offer.numberOffCandidates;
- tableModel.addRow(row);
- }
- }
- public void refreshTabled() {
- if (isFiltering == true) {
- tableModel.setRowCount(0);
- for (Offer offer : searchOffers) {
- Object row[] = new Object[5];
- row[0] = offer.company.name;
- row[1] = offer.position;
- row[2] = offer.tipes.name;
- row[3] = offer.descriptions;
- row[4] = offer.numberOffCandidates;
- tableModel.addRow(row);
- }
- } else {
- tableModel.setRowCount(0);
- for (Offer offer : offers) {
- Object row[] = new Object[5];
- row[0] = offer.company.name;
- row[1] = offer.position;
- row[2] = offer.tipes.name;
- row[3] = offer.descriptions;
- row[4] = offer.numberOffCandidates;
- tableModel.addRow(row);
- }
- }
- }
- public void clearAction() {
- if (isFiltering == false) {
- refreshTable();
- }
- }
- public void checkField() {
- String check = positionField.getText();
- String checkDescription = descriptionTextView.getText();
- if (check.equals("") || check.equals("position")) {
- JOptionPane.showMessageDialog(null, "imash prazno pole trqbva poziciq", " error",
- JOptionPane.ERROR_MESSAGE);
- } else if (checkDescription.length() == 0) {
- JOptionPane.showMessageDialog(null, "imash 1 prazno pole trqbva poziciq", " error",
- JOptionPane.ERROR_MESSAGE);
- } else {
- addOfferAction();
- }
- }
- public void showPanel() {
- OfferFrame offerframe = new OfferFrame(companies, tipes);
- offerframe.setVisible(false);
- candidatePanel = new CandidatePanel(this);
- candidatePanel.setSize(getWidth(), getHeight());
- getContentPane().add(candidatePanel);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement