Доброе утро.
Я создал логин класс и MainWindow классы. Когда пытаюсь ниже код сделать выдает ошибку, ошибку прикрепил:
Login.java
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. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. 87. 88. 89. 90. 91. 92. 93. 94. 95. 96. 97. 98. 99. 100. 101. 102. 103. 104. 105. 106. 107. 108. 109. 110. 111. 112. 113. 114. 115. 116. 117. 118. 119. 120. 121. 122. 123. 124. 125. 126. 127. 128. 129. 130. 131. 132. 133. 134. 135. 136. 137. 138. 139. 140. 141. 142. 143. 144. 145. 146. 147. 148. 149. 150. 151. 152. 153. 154. 155. 156. 157. 158. 159. 160. 161. 162. 163. 164. 165. 166. 167. 168. 169. 170. 171. 172. 173. 174. 175. 176. 177. 178. 179. 180. 181. 182. 183. 184. 185. 186. 187. 188. 189. 190. 191. 192.
package SafetyInspectionRegister;
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JComboBox;
import javax.swing.JButton;
import java.awt.Font;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import javax.swing.border.EtchedBorder;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import SafetyInspectionRegister.SafetyDatabase;
import SafetyInspectionRegister.MainWindow;
public class Login extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private JTextField loginField;
private JLabel label;
private JPasswordField passwordField;
private JLabel label_1;
SafetyDatabase _safetyDatabase = SafetyDatabase.getInstance();
public static String _cai, _password, _group;
public String _dbpassword, _dbgroup;
public boolean _isBlocked, _isFirstLogin = false;
/**
* Create the frame.
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public Login() {
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 175, 209);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
contentPane.setLayout(null);
JPanel panel = new JPanel();
panel.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
contentPane.add(panel);
panel.setBounds(0, 0, 170, 182);
panel.setLayout(null);
JLabel lblCai = new JLabel("Введите CAI");
lblCai.setFont(new Font("Tahoma", Font.PLAIN, 10));
lblCai.setBounds(10, 8, 86, 14);
panel.add(lblCai);
loginField = new JTextField();
loginField.setFont(new Font("Tahoma", Font.PLAIN, 11));
loginField.setBounds(10, 24, 152, 20);
panel.add(loginField);
loginField.setColumns(10);
label = new JLabel("Введите \u043Fар\u043E\u043B\u044C");
label.setFont(new Font("Tahoma", Font.PLAIN, 10));
label.setBounds(10, 55, 102, 14);
panel.add(label);
passwordField = new JPasswordField();
passwordField.setFont(new Font("Tahoma", Font.PLAIN, 10));
passwordField.setBounds(10, 72, 152, 20);
panel.add(passwordField);
label_1 = new JLabel("В\u044Bберите гру\u043F\u043Fу");
label_1.setFont(new Font("Tahoma", Font.PLAIN, 10));
label_1.setBounds(10, 104, 128, 14);
panel.add(label_1);
final JComboBox comboBox = new JComboBox();
comboBox.setFont(new Font("Tahoma", Font.PLAIN, 9));
comboBox.setBounds(10, 120, 152, 20);
comboBox.setModel(new DefaultComboBoxModel(new String[] {"User", "Super User", "Power User", "Administrator"}));
panel.add(comboBox);
comboBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
}
});
JButton okButton = new JButton("OK");
okButton.addActionListener(new ActionListener() {
@SuppressWarnings("deprecation")
public void actionPerformed(ActionEvent arg0) {
_cai = loginField.getText().trim();
_password = convertToMD5(passwordField.getText().trim());
_group = comboBox.getSelectedItem().toString();
if (_safetyDatabase.getUserInfo(_cai)) {
_dbpassword = _safetyDatabase._password;
_dbgroup = _safetyDatabase._groupName;
_isBlocked = _safetyDatabase._blocked;
_isFirstLogin = _safetyDatabase._firstLogin;
if (_dbpassword.equals(_password)) {
if (_dbgroup.equals(_group)) {
if (!_isBlocked) {
if (_isFirstLogin) {
JOptionPane.showMessageDialog(null,"С\u043Cе\u043Dите \u043Fар\u043E\u043B\u044C в \u043Cе\u043D\u044E \"\u041Dастр\u043Eй\u043Aа\"");
}
try {
MainWindow _mainWindow = new MainWindow();
_mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
_mainWindow.setVisible(true);
setVisible(false);
setVisible(false);
} catch(Exception e) {
JOptionPane.showMessageDialog(null, e);
}
}
else {
JOptionPane.showMessageDialog(null,"Ваш CAI заб\u043B\u043E\u043Aир\u043Eва\u043D");
}
}
else {
JOptionPane.showMessageDialog(null,"\u041Dевер\u043Dа\u044F гру\u043F\u043Fа");
}
}
else {
JOptionPane.showMessageDialog(null, "\u041Dевер\u043D\u044Bй \u043Fар\u043E\u043B\u044C");
}
}
else {
JOptionPane.showMessageDialog(null, "\u041Dевер\u043D\u044Bй CAI");
}
}
});
okButton.setFont(new Font("Tahoma", Font.PLAIN, 10));
okButton.setBounds(10, 151, 73, 23);
panel.add(okButton);
JButton cancelButton = new JButton("Cancel");
cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
System.exit(0);
}
});
cancelButton.setFont(new Font("Tahoma", Font.PLAIN, 10));
cancelButton.setBounds(87, 151, 75, 23);
panel.add(cancelButton);
}
public String convertToMD5(String orgPassword) {
String md5Password = "";
try {
// Create MessageDigest instance for MD5
MessageDigest md = MessageDigest.getInstance("MD5");
//Add password bytes to digest
md.update(orgPassword.getBytes());
//Get the hash's bytes
byte[] bytes = md.digest();
//This bytes[] has bytes in decimal format;
//Convert it to hexadecimal format
StringBuilder sb = new StringBuilder();
for(int i=0; i< bytes.length; i++)
{
sb.append(Integer.toString((bytes[i] & 0xff) + 0x100, 16).substring(1));
}
//Get complete hashed password in hex format
md5Password = sb.toString();
}
catch (NoSuchAlgorithmException e)
{
e.printStackTrace();
}
return md5Password;
}
}
Если убрать весь код из MainWindow то пустая форма нормально отображается. Вот код MainWindow, правда огромный:
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. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. 81. 82. 83. 84. 85. 86. 87. 88. 89. 90. 91. 92. 93. 94. 95. 96. 97. 98. 99. 100. 101. 102. 103. 104. 105. 106. 107. 108. 109. 110. 111. 112. 113. 114. 115. 116. 117. 118. 119. 120. 121. 122. 123. 124. 125. 126. 127. 128. 129. 130. 131. 132. 133. 134. 135. 136. 137. 138. 139. 140. 141. 142. 143. 144. 145. 146. 147. 148. 149. 150. 151. 152. 153. 154. 155. 156. 157. 158. 159. 160. 161. 162. 163. 164. 165. 166. 167. 168. 169. 170. 171. 172. 173. 174. 175. 176. 177. 178. 179. 180. 181. 182. 183. 184. 185. 186. 187. 188. 189. 190. 191. 192. 193. 194. 195. 196. 197. 198. 199. 200. 201. 202. 203. 204. 205. 206. 207. 208. 209. 210. 211. 212. 213. 214. 215. 216. 217. 218. 219. 220. 221. 222. 223. 224. 225. 226. 227. 228. 229. 230. 231. 232. 233. 234. 235. 236. 237. 238. 239. 240. 241. 242. 243. 244. 245. 246. 247. 248. 249. 250. 251. 252. 253. 254. 255. 256. 257. 258. 259. 260. 261. 262. 263. 264. 265. 266. 267. 268. 269. 270. 271. 272. 273. 274. 275. 276. 277. 278. 279. 280. 281. 282. 283. 284. 285. 286. 287. 288. 289. 290. 291. 292. 293. 294. 295. 296. 297. 298. 299. 300. 301. 302. 303. 304. 305. 306. 307. 308. 309. 310. 311. 312. 313. 314. 315. 316. 317. 318. 319. 320. 321. 322. 323. 324. 325. 326. 327. 328. 329. 330. 331. 332. 333. 334. 335. 336. 337. 338. 339. 340. 341. 342. 343. 344. 345. 346. 347. 348. 349. 350. 351. 352. 353. 354. 355. 356. 357. 358. 359. 360. 361. 362. 363. 364. 365. 366. 367. 368. 369. 370. 371. 372. 373. 374. 375. 376. 377. 378. 379. 380. 381. 382. 383. 384. 385. 386. 387. 388. 389. 390. 391. 392. 393. 394. 395. 396. 397. 398. 399. 400. 401. 402. 403. 404. 405. 406. 407. 408. 409. 410. 411. 412. 413. 414. 415. 416. 417. 418. 419. 420. 421. 422. 423. 424. 425. 426. 427. 428. 429. 430. 431. 432. 433. 434. 435. 436. 437. 438. 439. 440. 441. 442. 443. 444. 445. 446. 447. 448. 449. 450. 451. 452. 453. 454. 455. 456. 457. 458. 459. 460. 461. 462. 463. 464. 465. 466. 467. 468. 469. 470. 471. 472. 473. 474. 475. 476. 477. 478. 479. 480. 481. 482. 483. 484. 485. 486. 487. 488. 489. 490. 491. 492. 493. 494. 495. 496. 497. 498. 499. 500. 501. 502. 503. 504. 505. 506. 507. 508. 509. 510. 511. 512. 513. 514. 515. 516. 517. 518. 519. 520. 521. 522. 523. 524. 525. 526. 527. 528. 529. 530. 531. 532. 533. 534. 535. 536. 537. 538. 539. 540. 541. 542. 543. 544. 545. 546. 547. 548. 549. 550. 551. 552. 553. 554. 555. 556. 557. 558. 559. 560. 561. 562. 563. 564. 565. 566. 567. 568. 569. 570. 571. 572. 573. 574. 575. 576. 577. 578. 579. 580. 581. 582. 583. 584. 585. 586. 587. 588. 589. 590. 591. 592. 593. 594. 595. 596. 597. 598. 599. 600. 601. 602. 603. 604. 605. 606. 607. 608. 609. 610. 611. 612. 613. 614. 615. 616. 617. 618. 619. 620. 621. 622. 623. 624. 625. 626. 627. 628. 629. 630. 631. 632. 633. 634. 635. 636. 637. 638. 639. 640. 641. 642. 643. 644. 645. 646. 647. 648. 649. 650. 651. 652. 653. 654. 655. 656. 657. 658. 659. 660. 661. 662. 663. 664. 665. 666. 667. 668. 669. 670. 671. 672. 673. 674. 675. 676. 677. 678. 679. 680. 681. 682. 683. 684. 685. 686. 687. 688. 689. 690. 691. 692. 693. 694. 695. 696. 697. 698. 699. 700. 701. 702. 703. 704. 705. 706. 707. 708. 709. 710. 711. 712. 713. 714. 715. 716. 717. 718. 719. 720. 721. 722. 723. 724. 725. 726. 727. 728. 729. 730. 731. 732. 733. 734. 735. 736. 737. 738. 739. 740. 741. 742. 743. 744. 745. 746. 747. 748. 749. 750. 751. 752. 753. 754. 755. 756. 757. 758. 759. 760. 761. 762. 763. 764. 765. 766. 767. 768. 769. 770. 771. 772. 773. 774. 775. 776. 777. 778. 779. 780. 781. 782. 783. 784. 785. 786. 787. 788. 789. 790. 791. 792. 793. 794. 795. 796.
package SafetyInspectionRegister;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import javax.swing.JTable;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableColumnModel;
import javax.swing.table.TableColumn;
import javax.swing.table.TableColumnModel;
import java.util.Calendar;
import java.util.Vector;
import SafetyInspectionRegister.SafetyTableModel;
import SafetyInspectionRegister.SafetyDatabase;
import SafetyInspectionRegister.SearchSafetyDialog;
import SafetyInspectionRegister.SettingsSafetyDialog;
import SafetyInspectionRegister.SafetyTableCellRenderer;
import SafetyInspectionRegister.UpdateSafetyUserDialog;
import SafetyInspectionRegister.CreateSafetyUserDialog;
import SafetyInspectionRegister.EditSafetyDialog;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Frame;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.Dimension;
import java.net.URL;
import java.io.FileWriter;
import java.io.IOException;
import java.io.File;
import java.util.Date;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
/**
* \author rrtech@tengizchevroil.com
* \brief Реализация класса основного фрейма программы
* \version 1.0
*/
public class MainWindow extends JFrame
{
public static int count = 0;
public static int ID;
public static int TaskID;
public static Date CheckDate;
public String CAI;
public static String UserName;
public static int CompanyID = 0;
public static String CompanyName;
public static int BadgeNumber;
public static int FacilityID = 0;
public static String FacilityName = "";
public static int SubFacilityID = 0;
public static String SubFacilityName = "";
public static int StatusID = 0;
public static String StatusName = "";
public static int SafetyStatusID = 0;
public static String SafetyStatusName = "";
public static int RespPersonID = 0;
public static String RespPersonName = "";
public static Date RespPersonFinishDate;
public static int VerificationCategoryID = 0;
public static String VerificationCategoryName = "";
public static int SubVerificationCategoryID = 0;
public static String SubVerificationCategoryName = "";
public static String Comments = "";
public static String DepName;
public static boolean isUser = false;
public static String genDate;
public static int month, year, iteration, done, dbmonth, dbyear, planDone;
SettingsManager _settingsManager = SettingsManager.getInstance();
private static final long serialVersionUID = 1L;
/**\brief Наименование заголовка вкладки с информацией о взвешивании вагонов*/
private final String _safetyTablePaneTitle = "Резу\u043B\u044Cтат";
public static int workPlanCount = 0;
public static Vector<Integer> IDVector = new Vector<Integer>();
public static Vector<Integer> TaskIDVec = new Vector<Integer>();
public static Vector<String> checkDateVec = new Vector<String>();
public static Vector<String> CAIVec = new Vector<String>();
public static Vector<String> UserNameVec = new Vector<String>();
public static Vector<Integer> CompanyIDVec = new Vector<Integer>();
public static Vector<String> CompanyNameVec = new Vector<String>();
public static Vector<Integer> BadgeNumberVec = new Vector<Integer>();
public static Vector<Integer> FacilityIDVec = new Vector<Integer>();
public static Vector<String> FacilityNameVec = new Vector<String>();
public static Vector<Integer> SubFacilityIDVec = new Vector<Integer>();
public static Vector<String> SubFacilityNameVec = new Vector<String>();
public static Vector<Integer> StatusIDVec = new Vector<Integer>();
public static Vector<String> StatusNameVec = new Vector<String>();
public static Vector<Integer> VerificationCategoryIDVec = new Vector<Integer>();
public static Vector<String> VerificationCategoryNameVec = new Vector<String>();
public static Vector<Integer> SubVerificationCategoryIDVec = new Vector<Integer>();
public static Vector<String> SubVerificationCategoryNameVec = new Vector<String>();
public static Vector<Integer> SafetyStatusIDVec = new Vector<Integer>();
public static Vector<String> SafetyStatusNameVec = new Vector<String>();
public static Vector<String> CommentsVec = new Vector<String>();
public static Vector<String> RespPersonNameVec = new Vector<String>();
public static Vector<String> RespPersonFinishDateVec = new Vector<String>();
public static Vector<String> DepNameVec = new Vector<String>();
public static int firstRow = 0;
JScrollPane _safetyTablePane;
JTabbedPane _mainPane = new JTabbedPane();
BorderLayout _mainLayout = new BorderLayout();
JToolBar _mainToolBar = new JToolBar();
JButton _searchDccButton = new JButton();
JButton _exportButton = new JButton();
JButton _addButton = new JButton();
JButton _createTaskButton = new JButton();
JButton _settingsButton = new JButton();
JButton _edituserButton = new JButton();
JButton _newUserButton = new JButton();
JButton _sendMailButton = new JButton();
JButton _helpButton = new JButton();
JTable _safetyTable = new JTable();
SafetyTableModel _safetyModel = new SafetyTableModel();
SafetyUserTableModel _safetyUserModel = new SafetyUserTableModel();
SafetyDatabase _safetyDatabase = SafetyDatabase.getInstance();
private final JButton _exitButton = new JButton();
JLabel _monthLabel = new JLabel();
JLabel _CAILabel = new JLabel();
JLabel _CompanyLabel = new JLabel();
MainWindow()
{
isUser = false;//_safetyDatabase._groupName.equals("User");
this.setTitle("Систе\u043Cа регистрации и \u043A\u043E\u043Dтр\u043E\u043B\u044F \u043Fр\u043Eвер\u043E\u043A ТБ ЖД \u043Eтде\u043Bа");
this.setExtendedState(Frame.MAXIMIZED_BOTH);
this.getContentPane().setLayout(_mainLayout);
this.setMinimumSize(new Dimension(800, 600));
URL dccIconURL = getClass().getResource("icons/search.png");
ImageIcon dccIcon = new ImageIcon(dccIconURL);
_searchDccButton.setIcon(dccIcon);
_searchDccButton.setFocusable(false);
_searchDccButton.setToolTipText("\u041F\u043Eис\u043A");
_searchDccButton.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
SearchSafetyDialog _searchSafetyDialog = new SearchSafetyDialog();
_searchSafetyDialog.setLocationRelativeTo(null);
_searchSafetyDialog.setVisible(true);
if (_searchSafetyDialog.isExisted())
{
loadSafetyData(_searchSafetyDialog.criteria());
}
}
});
URL createURL = getClass().getResource("icons/create.png");
ImageIcon createIcon = new ImageIcon(createURL);
Calendar getPlanDate = Calendar.getInstance();
month = getPlanDate.get(Calendar.MONTH) + 1;
year = getPlanDate.get(Calendar.YEAR);
if (_safetyDatabase.getPlan(Login._cai, month)) {
dbyear = _safetyDatabase._year;
dbmonth = _safetyDatabase._month;
planDone = _safetyDatabase._done;
}
System.out.println(planDone);
_createTaskButton.setIcon(createIcon);
_createTaskButton.setFocusable(false);
_createTaskButton.setToolTipText("С\u043Eхра\u043Dит\u044C \u043Fр\u043Eвер\u043Eч\u043D\u044Bй \u043Bист");
_createTaskButton.addActionListener(new ActionListener()
{
@SuppressWarnings("static-access")
@Override
public void actionPerformed(ActionEvent e)
{
if (TaskIDVec.size() == 0) {
JOptionPane.showMessageDialog(null, "В\u044B \u043Dе с\u043Eздава\u043Bи \u043Fр\u043Eвер\u043Eч\u043D\u043Eг\u043E \u043Bиста");
}
if (workPlanCount > 0) {
_safetyDatabase.updateWorkPlan(_safetyDatabase._CAI, _safetyDatabase._month, workPlanCount);
}
for (int i = 0; i < TaskIDVec.size(); i++) {
_safetyDatabase.addNewUnicodeRow(Integer.parseInt(IDVector.elementAt(i).toString()),
Integer.parseInt(TaskIDVec.elementAt(i).toString()),
checkDateVec.elementAt(i).toString(),
CAIVec.elementAt(i).toString(),
UserNameVec.elementAt(i).toString(),
Integer.parseInt(CompanyIDVec.elementAt(i).toString()),
_safetyDatabase.convertToUnicode(CompanyNameVec.elementAt(i).toString()),
Integer.parseInt(BadgeNumberVec.elementAt(i).toString()),
Integer.parseInt(FacilityIDVec.elementAt(i).toString()),
_safetyDatabase.convertToUnicode(FacilityNameVec.elementAt(i).toString()),
Integer.parseInt(SubFacilityIDVec.elementAt(i).toString()),
_safetyDatabase.convertToUnicode(SubFacilityNameVec.elementAt(i).toString()),
Integer.parseInt(StatusIDVec.elementAt(i).toString()),
_safetyDatabase.convertToUnicode(StatusNameVec.elementAt(i).toString()),
Integer.parseInt(VerificationCategoryIDVec.elementAt(i).toString()),
_safetyDatabase.convertToUnicode(VerificationCategoryNameVec.elementAt(i).toString()),
Integer.parseInt(SubVerificationCategoryIDVec.elementAt(i).toString()),
_safetyDatabase.convertToUnicode(SubVerificationCategoryNameVec.elementAt(i).toString()),
Integer.parseInt(SafetyStatusIDVec.elementAt(i).toString()),
_safetyDatabase.convertToUnicode(SafetyStatusNameVec.elementAt(i).toString()),
_safetyDatabase.convertToUnicode(CommentsVec.elementAt(i).toString()),
RespPersonNameVec.elementAt(i).toString(),
RespPersonFinishDateVec.elementAt(i).toString(),
DepNameVec.elementAt(i).toString());
}
if (TaskIDVec.size() > 0) {
JOptionPane.showMessageDialog(null, "\u041Fр\u043Eвер\u043Eч\u043D\u044Bй \u043Bист с\u043Eхра\u043Dе\u043D");
_safetyDatabase.updateTaskRowCount(_safetyDatabase.staticID + 1);
_safetyDatabase.staticID = _safetyDatabase.getTaskRowCount();
_safetyDatabase.updateDone(CAI, dbyear, dbmonth, planDone);
}
IDVector.removeAllElements();
TaskIDVec.removeAllElements();
checkDateVec.removeAllElements();
CAIVec.removeAllElements();
UserNameVec.removeAllElements();
CompanyIDVec.removeAllElements();
CompanyNameVec.removeAllElements();
BadgeNumberVec.removeAllElements();
FacilityIDVec.removeAllElements();
FacilityNameVec.removeAllElements();
SubFacilityIDVec.removeAllElements();
SubFacilityNameVec.removeAllElements();
StatusIDVec.removeAllElements();
StatusNameVec.removeAllElements();
VerificationCategoryIDVec.removeAllElements();
VerificationCategoryNameVec.removeAllElements();
SubVerificationCategoryIDVec.removeAllElements();
SubVerificationCategoryNameVec.removeAllElements();
SafetyStatusIDVec.removeAllElements();
SafetyStatusNameVec.removeAllElements();
CommentsVec.removeAllElements();
RespPersonNameVec.removeAllElements();
RespPersonFinishDateVec.removeAllElements();
DepNameVec.removeAllElements();
}
});
URL addIconURL = getClass().getResource("icons/new.png");
ImageIcon addIcon = new ImageIcon(addIconURL);
_addButton.setIcon(addIcon);
_addButton.setFocusable(false);
_addButton.setToolTipText("Зарегистрир\u043Eват\u044C \u043D\u043Eв\u044Bй \u043Fр\u043Eвер\u043Eч\u043D\u044Bй \u043Bист");
_addButton.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
AddSafetyDialog _addSafetyDialog = new AddSafetyDialog();
_addSafetyDialog.setLocationRelativeTo(null);
_addSafetyDialog.setVisible(true);
}
});
URL settingsIconURL = getClass().getResource("icons/settings.png");
ImageIcon settingsIcon = new ImageIcon(settingsIconURL);
_settingsButton.setIcon(settingsIcon);
_settingsButton.setFocusable(false);
_settingsButton.setToolTipText("\u041Dастр\u043Eй\u043Aа");
_settingsButton.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
SettingsSafetyDialog _settingsSafetyDialog = new SettingsSafetyDialog();
_settingsSafetyDialog.setLocationRelativeTo(null);
_settingsSafetyDialog.setVisible(true);
}
});
URL userEditIconURL = getClass().getResource("icons/edituser.png");
ImageIcon userEditIcon = new ImageIcon(userEditIconURL);
_edituserButton.setIcon(userEditIcon);
_edituserButton.setFocusable(false);
_edituserButton.setToolTipText("Реда\u043Aтир\u043Eват\u044C \u043F\u043E\u043B\u044Cз\u043Eвате\u043B\u044F");
_edituserButton.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
UpdateSafetyUserDialog _editSafetyUserDialog = new UpdateSafetyUserDialog();
_editSafetyUserDialog.setLocationRelativeTo(null);
_editSafetyUserDialog.setVisible(true);
}
});
URL newUserIconURL = getClass().getResource("icons/adduser.png");
ImageIcon newUserIcon = new ImageIcon(newUserIconURL);
_newUserButton.setIcon(newUserIcon);
_newUserButton.setFocusable(false);
_newUserButton.setToolTipText("Д\u043Eбавит\u044C \u043F\u043E\u043B\u044Cз\u043Eвате\u043B\u044F");
_newUserButton.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
CreateSafetyUserDialog _createSafetyUserDialog = new CreateSafetyUserDialog();
_createSafetyUserDialog.setLocationRelativeTo(null);
_createSafetyUserDialog.setVisible(true);
}
});
URL sendmailIconURL = getClass().getResource("icons/sendmail.png");
ImageIcon sendmailIcon = new ImageIcon(sendmailIconURL);
_sendMailButton.setIcon(sendmailIcon);
_sendMailButton.setFocusable(false);
_sendMailButton.setToolTipText("\u041Eт\u043Fравит\u044C с\u043E\u043Eбще\u043Dие \u043Dа \u044D\u043B. \u043F\u043Eчту");
_sendMailButton.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
CreateSafetyUserDialog _createSafetyUserDialog = new CreateSafetyUserDialog();
_createSafetyUserDialog.setLocationRelativeTo(null);
_createSafetyUserDialog.setVisible(true);
}
});
URL HelpIconURL = getClass().getResource("icons/help.png");
ImageIcon helpIcon = new ImageIcon(HelpIconURL);
_helpButton.setIcon(helpIcon);
_helpButton.setFocusable(false);
_helpButton.setToolTipText("\u041F\u043E\u043C\u043Eщ\u044C");
_helpButton.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
try {
File f = new File(_settingsManager.getHelpPath());
Runtime.getRuntime().exec(_settingsManager.getWordPath() + " " + f.getAbsolutePath());
} catch (IOException e1) {
System.out.println(e1);
e1.printStackTrace();
}
}
});
URL exportIconURL = getClass().getResource("icons/export.png");
ImageIcon exportIcon = new ImageIcon(exportIconURL);
_exportButton.setIcon(exportIcon);
_exportButton.setFocusable(false);
_exportButton.setToolTipText("\u042D\u043Aс\u043F\u043Eрт");
final JFrame thisInstance = this;
_exportButton.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
// JFilechooser with overwrite existed file dialog -->
JFileChooser chooser = new JFileChooser()
{
private static final long serialVersionUID = 1;
@Override
public void approveSelection()
{
File f = getSelectedFile();
String path = f.getAbsolutePath();
if (!path.toUpperCase().endsWith(".CSV"))
{
path += ".csv";
}
f = new File(path);
if (f.exists() && getDialogType() == SAVE_DIALOG)
{
int result = JOptionPane.showConfirmDialog(thisInstance,
"The file exists, overwrite?", "Existing file",
JOptionPane.YES_NO_CANCEL_OPTION);
switch(result)
{
case JOptionPane.YES_OPTION:
super.approveSelection();
break;
case JOptionPane.CANCEL_OPTION:
super.cancelSelection();
break;
default:
return;
}
}
super.approveSelection();
}
};
// <-- JFilechooser with overwrite existed file dialog
FileNameExtensionFilter filter = new FileNameExtensionFilter("CSV files", "csv");
chooser.setFileFilter(filter);
int retValue = chooser.showSaveDialog(thisInstance);
if (retValue == JFileChooser.APPROVE_OPTION)
{
String path = chooser.getSelectedFile().getAbsolutePath();
if (!path.toUpperCase().endsWith(".CSV"))
{
path += ".csv";
}
//System.out.println(path);
exportToCSV(path);
}
}
});
URL exitURL = getClass().getResource("icons/exit.png");
ImageIcon exitIcon = new ImageIcon(exitURL);
_exitButton.setIcon(exitIcon);
_exitButton.setFocusable(false);
_exitButton.setToolTipText("В\u044Bх\u043Eд");
_exitButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
System.exit(0);
}
});
Calendar getDate = Calendar.getInstance();
genDate = getMonthYear(getDate.get(Calendar.MONTH) + 1, getDate.get(Calendar.YEAR));
month = getDate.get(Calendar.MONTH) + 1;
year = getDate.get(Calendar.YEAR);
if (_safetyDatabase.getPlan(Login._cai, month)) {
dbyear = _safetyDatabase._year;
dbmonth = _safetyDatabase._month;
iteration = _safetyDatabase._iteration;
done = _safetyDatabase._done;
if (month == 12 && iteration <= done && year == dbyear) {
_safetyDatabase.updatePlan(Login._cai, year + 1);
genDate = genDate + " \u043A\u043E\u043B\u043Bичеств\u043E \u043Eб\u044Fзате\u043B\u044C\u043D\u044Bх \u043Fр\u043Eвер\u043E\u043A " + iteration + ", В\u044B\u043F\u043E\u043B\u043Dе\u043D\u043E " + done;
}
else {
genDate = genDate + " \u043A\u043E\u043B\u043Bичеств\u043E \u043Eб\u044Fзате\u043B\u044C\u043D\u044Bх \u043Fр\u043Eвер\u043E\u043A " + iteration + ", В\u044B\u043F\u043E\u043B\u043Dе\u043D\u043E " + done;
}
}
else {
System.out.println("No CAI in WorkPlan");
}
_CAILabel.setForeground(Color.LIGHT_GRAY);
_CompanyLabel.setForeground(Color.LIGHT_GRAY);
_CAILabel.setText("Ваш CAI: " + _safetyDatabase._CAI + ", \u041F\u043E\u043B\u044Cз\u043Eвате\u043B\u044C: " + _safetyDatabase._username);
_CompanyLabel.setText("\u041A\u043E\u043C\u043Fа\u043Dи\u044F: " + _safetyDatabase._companyName + ", \u041D\u043E\u043Cер бейджа: " + _safetyDatabase._badgeNumber);
_monthLabel.setForeground(Color.BLUE);
_monthLabel.setText(genDate);
JPanel _monthLabelPanel = new JPanel();
_monthLabelPanel.setBorder(BorderFactory.createTitledBorder("И\u043Dф\u043Eр\u043Cаци\u044F"));
_monthLabelPanel.setLayout(new BoxLayout(_monthLabelPanel, BoxLayout.Y_AXIS));
_monthLabel.setMaximumSize(new Dimension(420,60));
_monthLabelPanel.add(_CAILabel);
_monthLabelPanel.add(_CompanyLabel);
_monthLabelPanel.add(_monthLabel);
_mainToolBar.add(_addButton);
_mainToolBar.add(_createTaskButton);
_mainToolBar.add(_searchDccButton);
_mainToolBar.add(_exportButton);
_mainToolBar.add(_settingsButton);
if (_safetyDatabase._groupName.equals("Administrator") || _safetyDatabase._groupName.equals("Power User")) {
_mainToolBar.add(_edituserButton);
_mainToolBar.add(_newUserButton);
}
_mainToolBar.add(_sendMailButton);
_mainToolBar.setFloatable(false);
_mainToolBar.add(_helpButton);
_mainToolBar.add(_exitButton);
_mainToolBar.add(_monthLabelPanel);
TableColumnModel cm = new DefaultTableColumnModel() {
private static final long serialVersionUID = 1L;
public void addColumn(TableColumn tc) {
tc.setMinWidth(100); // just for looks, really...
super.addColumn(tc);
}
};
//------------------
_safetyTablePane = new JScrollPane(_safetyTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
_safetyTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
_safetyTable.setColumnModel(cm);
if (!isUser) {
_safetyTable.setModel(_safetyModel);
resizeColumnWidth(_safetyTable, 2);
resizeColumnWidth(_safetyTable, 4);
resizeColumnWidth(_safetyTable, 6);
resizeColumnWidth(_safetyTable, 7);
resizeColumnWidth(_safetyTable, 9);
resizeColumnWidth(_safetyTable, 10);
resizeColumnWidth(_safetyTable, 11);
resizeColumnWidth(_safetyTable, 14);
}
else {
_safetyTable.setModel(_safetyUserModel);
resizeColumnWidth(_safetyTable, 1);
resizeColumnWidth(_safetyTable, 3);
resizeColumnWidth(_safetyTable, 5);
resizeColumnWidth(_safetyTable, 6);
resizeColumnWidth(_safetyTable, 8);
resizeColumnWidth(_safetyTable, 9);
resizeColumnWidth(_safetyTable, 10);
resizeColumnWidth(_safetyTable, 13);
}
_safetyTable.setDefaultRenderer(Object.class, new SafetyTableCellRenderer());
_safetyTable.addMouseListener(new MouseAdapter()
{
@Override
public void mouseClicked(MouseEvent e)
{
if (e.getClickCount() < 1)
{
return;
}
switch(_safetyTable.getSelectedColumn())
{
case SafetyTableModel.EDIT_COLUMN:
{
ID = Integer.parseInt(getTableCell(_safetyTable, "ID"));
TaskID = Integer.parseInt(getTableCell(_safetyTable, "ID \u041Fр\u043Eвер.\u041Bиста"));
CheckDate = getDate(_safetyTable, "Дата регистрации");
CAI = getTableCell(_safetyTable, "CAI");
UserName = getTableCell(_safetyTable, "\u041F\u043E\u043B\u044Cз\u043Eвате\u043B\u044C");
CompanyName = getTableCell(_safetyTable, "\u041A\u043E\u043C\u043Fа\u043Dи\u044F");
FacilityName = getTableCell(_safetyTable, "\u041Dазва\u043Dие \u043Eб\u044Aе\u043Aта");
SubFacilityName = getTableCell(_safetyTable, "\u041Dазва\u043Dие \u043F\u043Eд\u043Eб\u044Aе\u043Aта");
StatusName = getTableCell(_safetyTable, "Статус");
SafetyStatusName = getTableCell(_safetyTable, "Статус без\u043E\u043Fас\u043D\u043Eсти");
RespPersonName = getTableCell(_safetyTable, "\u041Fр\u043Eвер\u044F\u044Eщий");
RespPersonFinishDate = getDate(_safetyTable, "\u041A\u043E\u043Dеч\u043D\u044Bй де\u043D\u044C \u043Fр\u043Eвер\u043Aи");
VerificationCategoryName = getTableCell(_safetyTable, "\u041Dазва\u043Dие \u043Aатег\u043Eрии");
SubVerificationCategoryName = getTableCell(_safetyTable, "\u041Dазва\u043Dие \u043F\u043Eд\u043Aатег\u043Eрии");
Comments = getTableCell(_safetyTable, "\u041A\u043E\u043C\u043Cе\u043Dтарии");
DepName = getTableCell(_safetyTable, "Де\u043Fарта\u043Cе\u043Dт");
EditSafetyDialog _editSafetyDialog = new EditSafetyDialog();
_editSafetyDialog.setLocationRelativeTo(null);
_editSafetyDialog.setVisible(true);
//loadDccData(criteria);
break;
}
}
}
});
_mainPane.addTab(_safetyTablePaneTitle, _safetyTablePane);
_mainPane.setToolTipTextAt(0, "Quick search");
getContentPane().add(_mainPane, BorderLayout.CENTER);
getContentPane().add(_mainToolBar, BorderLayout.NORTH);
}
private void loadSafetyData(SafetyDatabase.SafetySearchCriteria_t criteria)
{
int size = 0;
if (!criteria.isValid())
{
return;
}
if (!isUser) {
size = _safetyModel.loadData(criteria);
}
else {
size = _safetyUserModel.loadData(criteria);
}
if (size == 0)
{
String title = _safetyTablePaneTitle + " (" + String.valueOf(size) + ")";
_mainPane.setTitleAt(_mainPane.indexOfComponent(_safetyTablePane), title);
_mainPane.setSelectedComponent(_safetyTablePane);
return;
}
String title = _safetyTablePaneTitle + " (" + String.valueOf(size) + ")";
_mainPane.setTitleAt(_mainPane.indexOfComponent(_safetyTablePane), title);
_mainPane.setSelectedComponent(_safetyTablePane);
}
public void resizeColumnWidth(JTable table, int column) {
DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel();
colModel.getColumn(column).setMinWidth(155);
}
public String getTableCell(JTable _safetyTable, String columnName) {
String cell = "";
try {
cell = _safetyTable.getModel().getValueAt(_safetyTable.getSelectedRow(),
_safetyTable.getColumn(columnName).getModelIndex()).toString();
} catch(Exception e) {
System.out.println(e);
cell = "Empty";
return cell;
}
return cell;
}
public Date getDate(JTable _safetyTable, String columnName) {
Date date = new Date();
String testDate = getTableCell(_safetyTable, columnName);
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
try {
date = formatter.parse(testDate);
} catch (ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
date = null;
return date;
}
return date;
}
private void exportToCSV(String filename)
{
try
{
if (!isUser) {
FileWriter fw = new FileWriter(filename);
fw.write(tableModelToCSV(_safetyModel));
fw.close();
}
else {
FileWriter fw = new FileWriter(filename);
fw.write(tableModelToCSV(_safetyUserModel));
fw.close();
}
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private String tableModelToCSV(AbstractTableModel model)
{
String result = new String();
int j = 0;
if (isUser) j = 0;
if (!isUser) j = 1;
for (int i = j; i < model.getColumnCount(); ++i)
{
if (i != j)
{
result += ",";
}
result += "\"" + model.getColumnName(i) + "\"";
}
result += "\n";
for (int row = 0; row < model.getRowCount(); ++row)
{
for (int column = j; column < model.getColumnCount(); ++column)
{
if (column != j)
{
result += ",";
}
result += "\"" + model.getValueAt(row, column).toString() + "\"";
}
result += "\n";
}
return result;
}
private String getMonthYear(int month, int year) {
String date = "";
if (month == 1) {
date = "За \u042F\u043Dвар\u044C " + year;
}
if (month == 2) {
date = "За Февра\u043B\u044C " + year;
}
if (month == 3) {
date = "За \u041Cарт " + year;
}
if (month == 4) {
date = "За А\u043Fре\u043B\u044C " + year;
}
if (month == 5) {
date = "За \u041Cай " + year;
}
if (month == 6) {
date = "За И\u044E\u043D\u044C " + year;
}
if (month == 7) {
date = "За И\u044E\u043B\u044C " + year;
}
if (month == 8) {
date = "За Август\u044C " + year;
}
if (month == 9) {
date = "За Се\u043Dт\u044Fбр\u044C " + year;
}
if (month == 10) {
date = "За \u041E\u043Aт\u044Fбр\u044C " + year;
}
if (month == 11) {
date = "За \u041D\u043E\u044Fбр\u044C " + year;
}
if (month == 12) {
date = "За Де\u043Aабр\u044C " + year;
}
return date;
}
}
|