Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.73 KB | None | 0 0
  1. package Frame;
  2.  
  3. import javax.swing.JFrame;
  4. import javax.swing.JOptionPane;
  5.  
  6. import java.util.ArrayList;
  7.  
  8. import javax.swing.GroupLayout;
  9. import javax.swing.GroupLayout.Alignment;
  10. import javax.swing.JComboBox;
  11. import javax.swing.JTextField;
  12. import javax.swing.LayoutStyle.ComponentPlacement;
  13. import javax.swing.table.DefaultTableModel;
  14.  
  15. import Model.*;
  16. import Panels.*;
  17.  
  18. import javax.swing.JTextPane;
  19. import javax.swing.JTextArea;
  20. import javax.swing.JButton;
  21. import java.awt.event.ActionListener;
  22. import java.awt.event.ActionEvent;
  23. import java.awt.event.MouseAdapter;
  24. import java.awt.event.MouseEvent;
  25. import javax.swing.JScrollPane;
  26. import javax.swing.JTable;
  27. import java.awt.Color;
  28. import java.awt.Font;
  29. import javax.swing.SwingConstants;
  30.  
  31. public class OfferFrame extends JFrame {
  32.  
  33. public ArrayList<Company> companies = new ArrayList<Company>();
  34. public ArrayList<Offer> offers = new ArrayList<Offer>();
  35. public ArrayList<Tipes> tipes = new ArrayList<Tipes>();
  36. public ArrayList<Offer> searchOffers;
  37. public ArrayList<Offer> selectedCompany;
  38.  
  39. public CandidatePanel candidatePanel;
  40.  
  41. public boolean isFiltering = false;
  42.  
  43. private JTextField positionField;
  44. private JComboBox companyComboBox;
  45. private JComboBox tipeComboBox;
  46. private JTextArea descriptionTextView;
  47. private JButton addOfferButton;
  48. private JTable table;
  49. public DefaultTableModel tableModel;
  50. private JButton removeButton;
  51. private JButton candidateButton;
  52. private JButton searchButton;
  53. private JTextField searchField;
  54. private JButton selectedSearchButton;
  55.  
  56. public OfferFrame(ArrayList<Company> companies, ArrayList<Tipes> tipes) {
  57. super("Job Offerts");
  58. setDefaultCloseOperation(EXIT_ON_CLOSE);
  59. setSize(800, 600);
  60.  
  61. this.companies = companies;
  62. this.tipes = tipes;
  63.  
  64. companyComboBox = new JComboBox();
  65. for (Company companie : companies) {
  66. companyComboBox.addItem(companie.name);
  67.  
  68. }
  69.  
  70. positionField = new JTextField("position");
  71. positionField.addMouseListener(new MouseAdapter() {
  72. @Override
  73. public void mouseClicked(MouseEvent e) {
  74. positionField.setText("");
  75.  
  76. }
  77. });
  78. positionField.setColumns(10);
  79.  
  80. tipeComboBox = new JComboBox();
  81. for (Tipes tipes2 : tipes) {
  82. tipeComboBox.addItem(tipes2.name);
  83. }
  84.  
  85. descriptionTextView = new JTextArea();
  86. descriptionTextView.addMouseListener(new MouseAdapter() {
  87. @Override
  88. public void mouseClicked(MouseEvent e) {
  89. descriptionTextView.setText("");
  90. }
  91. });
  92. descriptionTextView.setText("Descriptiion min 100 characters");
  93.  
  94. JButton addOfferButton = new JButton("Add");
  95. addOfferButton.setForeground(Color.GREEN);
  96. addOfferButton.addActionListener(new ActionListener() {
  97. public void actionPerformed(ActionEvent e) {
  98. checkField();
  99.  
  100. }
  101. });
  102.  
  103. JScrollPane scrollPane = new JScrollPane();
  104.  
  105. removeButton = new JButton("Remove");
  106. removeButton.addActionListener(new ActionListener() {
  107. public void actionPerformed(ActionEvent e) {
  108. offers.remove(table.getSelectedRow());
  109. refreshTabled();
  110. }
  111. });
  112. removeButton.setForeground(Color.RED);
  113.  
  114. candidateButton = new JButton("Candidate");
  115. candidateButton.addActionListener(new ActionListener() {
  116. public void actionPerformed(ActionEvent e) {
  117. showPanel();
  118. }
  119. });
  120. candidateButton.setFont(new Font("Tahoma", Font.BOLD, 24));
  121. candidateButton.setForeground(Color.ORANGE);
  122.  
  123. searchButton = new JButton("Search");
  124. searchButton.addActionListener(new ActionListener() {
  125. public void actionPerformed(ActionEvent e) {
  126. filterOffersByPosition();
  127. }
  128. });
  129. searchButton.setForeground(Color.BLUE);
  130. searchButton.setFont(new Font("Tahoma", Font.BOLD, 24));
  131.  
  132. searchField = new JTextField();
  133. searchField.addMouseListener(new MouseAdapter() {
  134. @Override
  135. public void mouseClicked(MouseEvent e) {
  136. searchField.setText("");
  137. }
  138. });
  139. searchField.setHorizontalAlignment(SwingConstants.CENTER);
  140. searchField.setText("Search");
  141. searchField.setColumns(10);
  142.  
  143. selectedSearchButton = new JButton("selectedsearch");
  144. selectedSearchButton.addActionListener(new ActionListener() {
  145. public void actionPerformed(ActionEvent e) {
  146. selectCompany();
  147. }
  148. });
  149. GroupLayout groupLayout = new GroupLayout(getContentPane());
  150. groupLayout.setHorizontalGroup(
  151. groupLayout.createParallelGroup(Alignment.LEADING)
  152. .addGroup(groupLayout.createSequentialGroup()
  153. .addContainerGap()
  154. .addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
  155. .addGroup(groupLayout.createSequentialGroup()
  156. .addGroup(groupLayout.createParallelGroup(Alignment.LEADING)
  157. .addGroup(groupLayout.createSequentialGroup()
  158. .addComponent(addOfferButton, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)
  159. .addPreferredGap(ComponentPlacement.RELATED, 38, Short.MAX_VALUE)
  160. .addComponent(removeButton, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE))
  161. .addComponent(tipeComboBox, 0, 238, Short.MAX_VALUE)
  162. .addComponent(descriptionTextView, GroupLayout.PREFERRED_SIZE, 238, Short.MAX_VALUE)
  163. .addComponent(positionField, GroupLayout.DEFAULT_SIZE, 238, Short.MAX_VALUE)
  164. .addComponent(companyComboBox, 0, 238, Short.MAX_VALUE))
  165. .addGap(32)
  166. .addComponent(selectedSearchButton, GroupLayout.PREFERRED_SIZE, 176, GroupLayout.PREFERRED_SIZE)
  167. .addGap(29)
  168. .addGroup(groupLayout.createParallelGroup(Alignment.TRAILING, false)
  169. .addComponent(searchButton, GroupLayout.DEFAULT_SIZE, 280, Short.MAX_VALUE)
  170. .addComponent(candidateButton, GroupLayout.DEFAULT_SIZE, 280, Short.MAX_VALUE)
  171. .addComponent(searchField)))
  172. .addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 746, GroupLayout.PREFERRED_SIZE))
  173. .addGap(19))
  174. );
  175. groupLayout.setVerticalGroup(
  176. groupLayout.createParallelGroup(Alignment.TRAILING)
  177. .addGroup(groupLayout.createSequentialGroup()
  178. .addGap(41)
  179. .addComponent(scrollPane, GroupLayout.PREFERRED_SIZE, 247, GroupLayout.PREFERRED_SIZE)
  180. .addPreferredGap(ComponentPlacement.RELATED, 31, Short.MAX_VALUE)
  181. .addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
  182. .addGroup(groupLayout.createSequentialGroup()
  183. .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
  184. .addComponent(companyComboBox, GroupLayout.PREFERRED_SIZE, 31, GroupLayout.PREFERRED_SIZE)
  185. .addComponent(selectedSearchButton, GroupLayout.PREFERRED_SIZE, 24, GroupLayout.PREFERRED_SIZE))
  186. .addPreferredGap(ComponentPlacement.RELATED)
  187. .addComponent(positionField, GroupLayout.PREFERRED_SIZE, 29, GroupLayout.PREFERRED_SIZE)
  188. .addPreferredGap(ComponentPlacement.RELATED)
  189. .addComponent(tipeComboBox, GroupLayout.PREFERRED_SIZE, 32, GroupLayout.PREFERRED_SIZE)
  190. .addPreferredGap(ComponentPlacement.RELATED)
  191. .addComponent(descriptionTextView, GroupLayout.PREFERRED_SIZE, 80, GroupLayout.PREFERRED_SIZE)
  192. .addGap(18)
  193. .addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
  194. .addComponent(addOfferButton)
  195. .addComponent(removeButton))
  196. .addContainerGap())
  197. .addGroup(groupLayout.createSequentialGroup()
  198. .addComponent(searchField, GroupLayout.PREFERRED_SIZE, 39, GroupLayout.PREFERRED_SIZE)
  199. .addGap(18)
  200. .addComponent(searchButton, GroupLayout.PREFERRED_SIZE, 41, GroupLayout.PREFERRED_SIZE)
  201. .addPreferredGap(ComponentPlacement.UNRELATED)
  202. .addComponent(candidateButton, GroupLayout.PREFERRED_SIZE, 86, GroupLayout.PREFERRED_SIZE)
  203. .addGap(38))))
  204. );
  205.  
  206. table = new JTable();
  207. String collums[] = { "Фирма", "Позиция", "Тип", "Описание", "Брой кандидати" };
  208. tableModel = new DefaultTableModel();
  209. tableModel.setColumnIdentifiers(collums);
  210. table.setModel(tableModel);
  211. scrollPane.setViewportView(table);
  212. getContentPane().setLayout(groupLayout);
  213. }
  214.  
  215. public void addOfferAction() {
  216.  
  217. Company company = companies.get(companyComboBox.getSelectedIndex());
  218. Tipes tipe = tipes.get(tipeComboBox.getSelectedIndex());
  219. Offer a = new Offer(company, positionField.getText().toLowerCase(), tipe, descriptionTextView.getText());
  220. offers.add(a);
  221. refreshTable();
  222.  
  223. }
  224.  
  225. public void filterOffersByPosition() {
  226. searchOffers = new ArrayList<Offer>();
  227. isFiltering = false;
  228. String a = searchField.getText().toLowerCase();
  229. for (Offer offer : offers) {
  230. if (offer.position.contains(a.toLowerCase())) {
  231. searchOffers.add(offer);
  232. isFiltering = true;
  233. refreshTabled();
  234. }
  235.  
  236. }
  237. }
  238. public void selectCompany() {
  239. selectedCompany = new ArrayList<Offer>();
  240. //isFiltering = false;
  241. Company compani = companies.get(table.getSelectedRow());
  242.  
  243. for (Offer offer : offers) {
  244. if(compani.companyID == offer.company.companyID) {
  245. selectedCompany.add(offer);
  246. isFiltering = true;
  247. refreshTabled();
  248. }
  249. }
  250.  
  251.  
  252. }
  253.  
  254. public void refreshTable() {
  255. tableModel.setRowCount(0);
  256. for (Offer offer : offers) {
  257. Object row[] = new Object[5];
  258. row[0] = offer.company.name;
  259. row[1] = offer.position;
  260. row[2] = offer.tipes.name;
  261. row[3] = offer.descriptions;
  262. row[4] = offer.numberOffCandidates;
  263. tableModel.addRow(row);
  264.  
  265. }
  266. }
  267.  
  268. public void refreshTabled() {
  269. if (isFiltering == true) {
  270. tableModel.setRowCount(0);
  271. for (Offer offer : searchOffers) {
  272. Object row[] = new Object[5];
  273. row[0] = offer.company.name;
  274. row[1] = offer.position;
  275. row[2] = offer.tipes.name;
  276. row[3] = offer.descriptions;
  277. row[4] = offer.numberOffCandidates;
  278. tableModel.addRow(row);
  279. }
  280. } else {
  281.  
  282. tableModel.setRowCount(0);
  283. for (Offer offer : offers) {
  284. Object row[] = new Object[5];
  285. row[0] = offer.company.name;
  286. row[1] = offer.position;
  287. row[2] = offer.tipes.name;
  288. row[3] = offer.descriptions;
  289. row[4] = offer.numberOffCandidates;
  290. tableModel.addRow(row);
  291.  
  292. }
  293. }
  294. }
  295.  
  296. public void clearAction() {
  297. if (isFiltering == false) {
  298. refreshTable();
  299. }
  300. }
  301.  
  302. public void checkField() {
  303. String check = positionField.getText();
  304. String checkDescription = descriptionTextView.getText();
  305. if (check.equals("") || check.equals("position")) {
  306. JOptionPane.showMessageDialog(null, "imash prazno pole trqbva poziciq", " error",
  307. JOptionPane.ERROR_MESSAGE);
  308.  
  309. } else if (checkDescription.length() == 0) {
  310. JOptionPane.showMessageDialog(null, "imash 1 prazno pole trqbva poziciq", " error",
  311. JOptionPane.ERROR_MESSAGE);
  312.  
  313. } else {
  314. addOfferAction();
  315. }
  316.  
  317. }
  318.  
  319. public void showPanel() {
  320.  
  321. OfferFrame offerframe = new OfferFrame(companies, tipes);
  322. offerframe.setVisible(false);
  323. candidatePanel = new CandidatePanel(this);
  324. candidatePanel.setSize(getWidth(), getHeight());
  325. getContentPane().add(candidatePanel);
  326. }
  327. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement