public static void main(String[] args) { // StartUpService.startUpData(); Service.sortTrailerArrival(); for (Trailer trailer : Dao.getTrailer()) { Service.setSubOrderEarliestLoadingTime(trailer); } StartUpService.sortSubOrdersDao(); Service.createLoadingBaySchedule(Dao.getSubOrders()); trailerView = new TrailerView(); loadingBayView = new LoadingBayView(); externalSystemView = new ExternalSystemView(); }
// This method is called when a button is pressed. public void actionPerformed(ActionEvent e) { if (e.getSource() == btnOk) { String name = txfName.getText().trim(); if (name.length() == 0) { // TODO: notify user return; } String wageStr = txfWage.getText().trim(); if (wageStr.length() == 0) { // TODO: notify user return; } int wage = -1; try { wage = Integer.parseInt(wageStr); } catch (NumberFormatException ex) { // TODO: notify user return; } if (wage < 0) { // TODO: notify user return; } Company company = null; if (cbxCompanies.getSelectedIndex() >= 1) { company = (Company) cbxCompanies.getItemAt(cbxCompanies.getSelectedIndex()); } /** ** update storage *** */ if (employee == null) { Employee newEmployee = service.createEmployee(name, wage); if (company != null) service.updateCompanyOfEmployee(newEmployee, company); } else { if (!employee.getName().equals(name) || employee.getWage() != wage) service.updateEmployee(employee, name, wage); if (employee.getCompany() != company) service.updateCompanyOfEmployee(employee, company); } closedByOk = true; EmployeeCUDialog.this.setVisible(false); } if (e.getSource() == btnCancel) { closedByOk = false; EmployeeCUDialog.this.setVisible(false); } }
public MainFrame() { Service.createAndStoreSomeObjects(); pnlContent = (JPanel) this.getContentPane(); pnlContent.setLayout(null); pnlScreen = new JPanel(); pnlContent.add(pnlScreen); pnlScreen.setSize(300, 380); pnlScreen.setLocation(10, 10); pnlScreen.setLayout(null); pnlButtons = new JPanel(); pnlContent.add(pnlButtons); pnlButtons.setSize(300, 60); pnlButtons.setLocation(10, 400); pnlButtons.setLayout(null); btnHome = new JButton("Home"); pnlButtons.add(btnHome); btnHome.setSize(70, 30); btnHome.setLocation(115, 10); btnHome.addActionListener(controller); // --------------------------------------------------------------------- Color color = new Color(99, 184, 255); // steelblue pnlMain = new MainPanel(this); pnlMain.setName("Main"); pnlMain.setBackground(color); pnlMain.setLayout(null); pnlScreen.add(pnlMain, "Main"); pnlTexts = new TextsPanel(this); pnlTexts.setName("Texts"); pnlScreen.add(pnlTexts, "Texts"); pnlTexts.setBackground(color); pnlTexts.setLayout(null); pnlCalls = new CallsPanel(this); pnlCalls.setName("Calls"); pnlScreen.add(pnlCalls, "Calls"); pnlCalls.setBackground(color); pnlCalls.setLayout(null); pnlContacts = new ContactsPanel(this); pnlContacts.setName("Contacts"); pnlScreen.add(pnlContacts, "Contacts"); pnlContacts.setBackground(color); pnlContacts.setLayout(null); showPanel("Main"); }
public void fillCbxCompanies() { DefaultComboBoxModel<Company> cbxCompaniesModel = new DefaultComboBoxModel<Company>(service.getAllCompanies().toArray(new Company[0])); cbxCompaniesModel.insertElementAt(new Company("-- none --", 0), 0); cbxCompanies.setModel(cbxCompaniesModel); }
private class Controller implements ActionListener { private boolean closedByOk = false; private Employee employee = null; private Service service = Service.getService(); public void fillCbxCompanies() { DefaultComboBoxModel<Company> cbxCompaniesModel = new DefaultComboBoxModel<Company>(service.getAllCompanies().toArray(new Company[0])); cbxCompaniesModel.insertElementAt(new Company("-- none --", 0), 0); cbxCompanies.setModel(cbxCompaniesModel); } private void updateView() { if (employee != null) { txfName.setText(employee.getName()); txfWage.setText("" + employee.getWage()); Company companyOfEmployee = employee.getCompany(); if (companyOfEmployee == null) cbxCompanies.setSelectedIndex(0); else { int index = 0; boolean found = false; int i = 0; while (!found && i < cbxCompanies.getItemCount()) { Company company = cbxCompanies.getItemAt(i); if (company == companyOfEmployee) { found = true; index = i; } else i++; } cbxCompanies.setSelectedIndex(index); } } else { txfName.setText(""); txfWage.setText(""); cbxCompanies.setSelectedIndex(0); } } // This method is called when a button is pressed. public void actionPerformed(ActionEvent e) { if (e.getSource() == btnOk) { String name = txfName.getText().trim(); if (name.length() == 0) { // TODO: notify user return; } String wageStr = txfWage.getText().trim(); if (wageStr.length() == 0) { // TODO: notify user return; } int wage = -1; try { wage = Integer.parseInt(wageStr); } catch (NumberFormatException ex) { // TODO: notify user return; } if (wage < 0) { // TODO: notify user return; } Company company = null; if (cbxCompanies.getSelectedIndex() >= 1) { company = (Company) cbxCompanies.getItemAt(cbxCompanies.getSelectedIndex()); } /** ** update storage *** */ if (employee == null) { Employee newEmployee = service.createEmployee(name, wage); if (company != null) service.updateCompanyOfEmployee(newEmployee, company); } else { if (!employee.getName().equals(name) || employee.getWage() != wage) service.updateEmployee(employee, name, wage); if (employee.getCompany() != company) service.updateCompanyOfEmployee(employee, company); } closedByOk = true; EmployeeCUDialog.this.setVisible(false); } if (e.getSource() == btnCancel) { closedByOk = false; EmployeeCUDialog.this.setVisible(false); } } }
public void checkStatus() { boolean nothingToReport = true; Set<Stock> critical = Service.getCriticalStocks(75); if (critical != null && critical.size() > 0) { if (critical.size() <= 1) { String name = "Unnamed"; for (Stock s : critical) { if (s != null && s.getName() != null && s.getName().trim().length() > 0) { name = s.getName(); break; } } lblStocks.setText( "<html><strong style=\"color:#777700;\">We are in a bit of a pickle</strong>: one of your stocks (" + name + ") is running out of space. </html>"); } else { String names = ""; for (Stock s : critical) { if (s != null && s.getName() != null && s.getName().trim().length() > 0) { if (names.length() > 0) names += ", "; names += s.getName(); } else { if (names.length() > 0) names += ", "; names += "Unnamed"; } } lblStocks.setText( "<html><strong style=\"color:red;\">You are in a world of hurt</strong>: " + critical.size() + " of your stocks (" + names + ") are running out of space. </html>"); } nothingToReport = false; } else { lblStocks.setText( "<html><strong style=\"color:green;\">Your storage is in tip-top shape</strong>: there are no Stocks running out of space. </html>"); } Set<Tray> expiring = Service.getExpiringTrays(); if (expiring != null && expiring.size() > 0) { Map<Stock, Integer> stocks = new HashMap<Stock, Integer>(); for (Tray tray : expiring) { if (tray != null && tray.getStorageUnit() != null && tray.getStorageUnit().getStock() != null) { Stock stock = tray.getStorageUnit().getStock(); if (stocks.containsKey(stock)) { stocks.put(stock, stocks.get(stock) + 1); } else { stocks.put(stock, 1); } } else { if (stocks.containsKey(null)) { stocks.put(null, stocks.get(null) + 1); } else { stocks.put(null, 1); } } } String names = ""; for (Stock s : stocks.keySet()) { if (s != null && s.getName() != null && s.getName().trim().length() > 0) { if (names.length() > 0) names += ", "; names += s.getName(); names += " - " + stocks.get(s); } else if (s == null) { if (names.length() > 0) names += ", "; names += "Unknown stock"; names += " - " + stocks.get(s); } } lblExpiring.setText( "<html><strong style=\"color:#777700;\">The situation is getting hairy</strong>: the following stocks have aging trays: " + names + ". </html>"); nothingToReport = false; } else { lblExpiring.setText( "<html><strong style=\"color:green;\">There is no problem with expiring trays</strong>: there are no expiring trays at the moment. </html>"); } Set<Tray> wasted = Service.getWastedTrays(); if (wasted != null && wasted.size() > 0) { Map<Stock, Integer> stocks = new HashMap<Stock, Integer>(); for (Tray tray : wasted) { if (tray != null && tray.getStorageUnit() != null && tray.getStorageUnit().getStock() != null) { Stock stock = tray.getStorageUnit().getStock(); if (stocks.containsKey(stock)) { stocks.put(stock, stocks.get(stock) + 1); } else { stocks.put(stock, 1); } } else { if (stocks.containsKey(null)) { stocks.put(null, stocks.get(null) + 1); } else { stocks.put(null, 1); } } } String names = ""; for (Stock s : stocks.keySet()) { if (s != null && s.getName() != null && s.getName().trim().length() > 0) { if (names.length() > 0) names += ", "; names += s.getName(); names += " - " + stocks.get(s); } else if (s == null) { if (names.length() > 0) names += ", "; names += "Unknown stock"; names += " - " + stocks.get(s); } } lblWasted.setText( "<html><strong style=\"color:red;\">The reality is getting very sad</strong>: the following stocks have wasted trays: " + names + ". </html>"); nothingToReport = false; } else { lblWasted.setText( "<html><strong style=\"color:green;\">There is no problem with wasted trays</strong>: there are no wasted trays at the moment. </html>"); } if (nothingToReport) { this.setPreferredSize(new Dimension(0, 0)); } else { this.setPreferredSize(new Dimension(0, 50)); } }