/* * This file is part of the aidGer project. * * Copyright (C) 2010-2013 The aidGer Team * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package de.aidger.view.forms; import static de.aidger.utils.Translation._; import javax.swing.JPanel; import javax.swing.SwingUtilities; import de.aidger.model.models.CostUnit; import de.aidger.view.utils.InputPatternFilter; /** * A form used for editing / creating new contracts. * * @author aidGer Team */ @SuppressWarnings("serial") public class CostUnitEditorForm extends JPanel { /** * A flag whether the form is in edit mode. */ private boolean editMode = false; /** * Constructs a cost unit editor form. * * @param costUnit * the cost unit that will be edited */ public CostUnitEditorForm(CostUnit costUnit) { if (costUnit != null) { editMode = true; } initComponents(); InputPatternFilter.addFilter(txtCostUnit, "[0-9]{0,8}"); SwingUtilities.invokeLater(new Runnable() { public void run() { txtCostUnit.requestFocusInWindow(); } }); if (editMode) { txtCostUnit.setText(costUnit.getCostUnit()); txtFunds.setText(costUnit.getFunds()); txtTokenDB.setText(costUnit.getTokenDB()); } } /** * Returns whether the form is in edit mode. * * @return whether the form is in edit mode */ public boolean isEditMode() { return editMode; } /** * Returns the cost unit. * * @return the cost unit */ public String getCostUnit() { return txtCostUnit.getText(); } /** * Returns the funds. * * @return the funds */ public String getFunds() { return txtFunds.getText(); } /** * Returns the database token. * * @return the database token */ public String getTokenDB() { return txtTokenDB.getText(); } /** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { java.awt.GridBagConstraints gridBagConstraints; lblCostUnit = new javax.swing.JLabel(); lblFunds = new javax.swing.JLabel(); lblTokenDB = new javax.swing.JLabel(); txtCostUnit = new javax.swing.JTextField(); txtFunds = new javax.swing.JTextField(); txtTokenDB = new javax.swing.JTextField(); setLayout(new java.awt.GridBagLayout()); lblCostUnit.setText(_("Cost unit")); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10); add(lblCostUnit, gridBagConstraints); lblCostUnit.getAccessibleContext().setAccessibleDescription("costUnit"); lblFunds.setText(_("Funds")); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10); add(lblFunds, gridBagConstraints); lblFunds.getAccessibleContext().setAccessibleDescription("funds"); lblTokenDB.setText(_("Database token")); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 2; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10); add(lblTokenDB, gridBagConstraints); lblTokenDB.getAccessibleContext().setAccessibleDescription("tokenDB"); txtCostUnit.setMinimumSize(new java.awt.Dimension(200, 25)); txtCostUnit.setPreferredSize(new java.awt.Dimension(200, 25)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10); add(txtCostUnit, gridBagConstraints); txtFunds.setMinimumSize(new java.awt.Dimension(200, 25)); txtFunds.setPreferredSize(new java.awt.Dimension(200, 25)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 1; gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10); add(txtFunds, gridBagConstraints); txtTokenDB.setMinimumSize(new java.awt.Dimension(200, 25)); txtTokenDB.setPreferredSize(new java.awt.Dimension(200, 25)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 2; gridBagConstraints.insets = new java.awt.Insets(10, 10, 10, 10); add(txtTokenDB, gridBagConstraints); }// </editor-fold>//GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JLabel lblCostUnit; private javax.swing.JLabel lblFunds; private javax.swing.JLabel lblTokenDB; private javax.swing.JTextField txtCostUnit; private javax.swing.JTextField txtFunds; private javax.swing.JTextField txtTokenDB; // End of variables declaration//GEN-END:variables }