/** * Constructs a financial category editor form. * * @param fc * the financial category that will be edited */ public FinancialCategoryEditorForm(FinancialCategory fc, EditorTab tab) { this.tab = tab; initComponents(); SwingUtilities.invokeLater(new Runnable() { public void run() { txtName.requestFocusInWindow(); } }); // add input filters InputPatternFilter.addFilter(txtYear, "[0-9]{0,4}"); hlpYear.setToolTipText(_("Only a year in 4 digits is allowed.")); if (fc != null) { txtName.setText(fc.getName()); txtYear.setText(String.valueOf(fc.getYear())); for (int i = 0; i < fc.getCostUnits().length; ++i) { addNewCostUnit(); CostUnitLine fl = costUnitLines.get(i); fl.cmbCostUnit.setSelectedItem(new CostUnit().getCostUnit(fc.getCostUnits()[i])); fl.txtBudgetCosts.setText(String.valueOf(fc.getBudgetCosts()[i])); } } else { addNewCostUnit(); } }
/** * Adds a new cost unit line to the form. */ private void addNewCostUnit() { GridBagConstraints gridBagConstraints; JLabel lblCostUnit = new JLabel(); lblCostUnit.setText(_("Cost unit")); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = GridBagConstraints.RELATIVE; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10); add(lblCostUnit, gridBagConstraints); lblCostUnit.getAccessibleContext() .setAccessibleDescription("costUnits"); ComboBoxModel costUnitModel = new ComboBoxModel(DataType.CostUnit); List<CostUnit> costUnits = (new CostUnit()).getAll(); for(CostUnit costUnit : costUnits) { costUnitModel.addModel(costUnit); } JComboBox cmbCostUnit = new JComboBox(); cmbCostUnit.setModel(costUnitModel); if(cmbCostUnit.getItemCount() > 0) cmbCostUnit.setSelectedItem(null); tab.getListModels().add(costUnitModel); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = GridBagConstraints.RELATIVE; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10); add(cmbCostUnit, gridBagConstraints); JLabel lblBudgetCosts = new JLabel(); lblBudgetCosts.setText(_("Budget Costs")); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 2; gridBagConstraints.gridy = GridBagConstraints.RELATIVE; gridBagConstraints.anchor = GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(10, 35, 10, 10); add(lblBudgetCosts, gridBagConstraints); lblBudgetCosts.getAccessibleContext().setAccessibleDescription( "budgetCosts"); JTextField txtBudgetCosts = new JTextField(); txtBudgetCosts.setMinimumSize(new java.awt.Dimension(200, 25)); txtBudgetCosts.setPreferredSize(new java.awt.Dimension(200, 25)); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 3; gridBagConstraints.gridy = GridBagConstraints.RELATIVE; gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10); add(txtBudgetCosts, gridBagConstraints); InputPatternFilter.addFilter(txtBudgetCosts, "[0-9]+"); HelpLabel hlpBudgetCosts = new HelpLabel(); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 4; gridBagConstraints.gridy = GridBagConstraints.RELATIVE; gridBagConstraints.fill = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(10, 0, 10, 10); add(hlpBudgetCosts, gridBagConstraints); hlpBudgetCosts.setToolTipText(_("Only a number is allowed.")); JButton btnPlusMinus = new JButton(); gridBagConstraints = new GridBagConstraints(); gridBagConstraints.gridx = 5; CostUnitLine fl = new CostUnitLine(lblCostUnit, cmbCostUnit, lblBudgetCosts, txtBudgetCosts, hlpBudgetCosts, btnPlusMinus); if (costUnitLines.isEmpty()) { btnPlusMinus.setIcon(new ImageIcon(getClass().getResource( "/de/aidger/res/icons/plus-small.png"))); gridBagConstraints.gridy = 1; btnPlusMinus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { addNewCostUnit(); } }); } else { gridBagConstraints.gridy = GridBagConstraints.RELATIVE; btnPlusMinus.setAction(new RemoveCostUnitAction(fl)); } add(btnPlusMinus, gridBagConstraints); costUnitLines.add(fl); }