@Override public void handle(ActionEvent event) { if (event.getSource() instanceof CheckBox) { for (Entry<String, CheckBox> entry : propertiesCb.entrySet()) { CheckBox cb = entry.getValue(); String propertyName = entry.getKey(); if (cb.isSelected()) { propertiesTf.get(propertyName).setDisable(false); } else { propertiesTf.get(propertyName).setDisable(true); } } } }
public void newFile() { infoTa.setText(""); selectProviderCb.setValue(providers.get(0).getName()); weightTf.setText("0.0"); for (Entry<String, TextField> entry : propertiesTf.entrySet()) { String propertyName = entry.getKey(); TextField tf = entry.getValue(); CheckBox cb = propertiesCb.get(propertyName); tf.setText("0.0"); tf.setDisable(true); cb.setSelected(false); } file = null; mainStage.setTitle("unknown"); }
public void open(File f) { Properties open = new Properties(); InputStream input = null; try { input = new FileInputStream(f); open.load(input); selectProviderCb.setValue(open.getProperty("provider")); selectGrainCb.setValue(open.getProperty("grain")); weightTf.setText(open.getProperty("weight")); infoTa.setText(open.getProperty("info")); for (Entry<String, TextField> entry : propertiesTf.entrySet()) { String propertyName = entry.getKey(); TextField tf = entry.getValue(); CheckBox cb = propertiesCb.get(propertyName); tf.setText(open.getProperty(propertyName)); if (open.getProperty(propertyName + "_ENABLED").equals("ON")) { tf.setDisable(false); cb.setSelected(true); } else { tf.setDisable(true); cb.setSelected(false); } } mainStage.setTitle(f.getName()); } catch (Exception ex) { infoTa.setText("Не могу открыть файл"); } finally { if (input != null) { try { input.close(); } catch (IOException e) { e.printStackTrace(); } } } }
public void save(File f) { Properties save = new Properties(); OutputStream output = null; try { save.setProperty("provider", selectProviderCb.getValue()); save.setProperty("grain", selectGrainCb.getValue()); save.setProperty("weight", weightTf.getText()); save.setProperty("info", infoTa.getText()); for (Entry<String, TextField> entry : propertiesTf.entrySet()) { TextField tf = entry.getValue(); String propertyName = entry.getKey(); save.setProperty(propertyName, tf.getText()); if (tf.isDisable()) { save.setProperty(propertyName + "_ENABLED", "OFF"); } else { save.setProperty(propertyName + "_ENABLED", "ON"); } } output = new FileOutputStream(f); save.store(output, null); mainStage.setTitle(f.getName()); } catch (Exception ex) { infoTa.setText("Не могу сохранить в файл"); } finally { if (output != null) { try { output.close(); } catch (IOException e) { e.printStackTrace(); } } } }
public void HandlerCalcPriceButton(ActionEvent event) { try { grain = getGrain(selectGrainCb.getValue()); System.out.println("> " + grain.getName()); try { grain.setWeight(Double.parseDouble(weightTf.getText())); } catch (NumberFormatException e) { weightTf.requestFocus(); throw new NumberFormatException("Вес партии зерна"); } for (Entry<String, TextField> entry : propertiesTf.entrySet()) { TextField tf = entry.getValue(); String propertyName = entry.getKey(); System.out.println("\t> " + propertyName); if (!tf.isDisable()) { try { grain.getProperty(propertyName).setValue(Double.parseDouble(tf.getText())); } catch (NumberFormatException e) { tf.requestFocus(); throw new NumberFormatException(grain.getProperty(propertyName).getDescription()); } grain.getProperty(propertyName).setEnabled(true); } else { grain.getProperty(propertyName).setEnabled(false); } } System.out.println("> before calculator"); PriceCalculator calculator = new PriceCalculator(grain, dao); calculator.calculatePrice(); infoTa.setText(calculator.toString()); Supply supply = new Supply(); supply.setProvider(selectProviderCb.getValue()); supply.setDate(new Date(Calendar.getInstance().getTimeInMillis())); // supply.setGrain(grain.getName()); supply.setGrain(grain.getDescription()); supply.setWeight(grain.getWeight()); supply.setPrice(calculator.getPrice()); dao.saveSupply(supply); } catch (RestrictiveConditionException e) { Utils.showErrorDialog("Ограшичительные кондиции!", e); infoTa.clear(); } catch (DataBaseException e) { Utils.showErrorDialog("Обшибка базы данных!", e); infoTa.clear(); } catch (NumberFormatException e) { Utils.showErrorDialog("Неверный ввод!", e); infoTa.clear(); } catch (Exception ex) { Utils.showErrorDialog("Ошибка!", ex); infoTa.clear(); } }